diff --git a/src/Base/VectorPy.xml b/src/Base/VectorPy.xml index dad1536444..1dfa45cfe9 100644 --- a/src/Base/VectorPy.xml +++ b/src/Base/VectorPy.xml @@ -143,6 +143,17 @@ Normalizes in-place this vector to the length of 1.0. Checks if the distance between the points represented by this vector and `vector2` is less or equal to the given tolerance. +vector2 : Base.Vector +tol : float + + + + + isParallel(vector2, tol=0) -> bool + +Checks if this vector and `vector2` are +parallel less or equal to the given tolerance. + vector2 : Base.Vector tol : float diff --git a/src/Base/VectorPyImp.cpp b/src/Base/VectorPyImp.cpp index a22b15a904..80655e1429 100644 --- a/src/Base/VectorPyImp.cpp +++ b/src/Base/VectorPyImp.cpp @@ -377,6 +377,26 @@ PyObject* VectorPy::isEqual(PyObject* args) return Py::new_reference_to(eq); } +PyObject* VectorPy::isParallel(PyObject* args) +{ + PyObject* obj = nullptr; + double tolerance = 0; + if (!PyArg_ParseTuple(args, "O!d", &(VectorPy::Type), &obj, &tolerance)) { + return nullptr; + } + + VectorPy* vec = static_cast(obj); + + VectorPy::PointerType v1_ptr = getVectorPtr(); + VectorPy::PointerType v2_ptr = vec->getVectorPtr(); + + double dot = abs((*v1_ptr)*(*v2_ptr)); + double mag = v1_ptr->Length()*v2_ptr->Length(); + + Py::Boolean parallel(abs(dot-mag) < tolerance); + return Py::new_reference_to(parallel); +} + PyObject* VectorPy::scale(PyObject* args) { double factorX = 0.0;