AppPartDesignPy.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <Python.h>
00027 #endif
00028
00029 #include <Base/GeometryPyCXX.h>
00030 #include <Base/VectorPy.h>
00031 #include <Base/Tools.h>
00032
00033 static PyObject * makeFilletArc(PyObject *self, PyObject *args)
00034 {
00035 PyObject *pM1;
00036 PyObject *pP;
00037 PyObject *pQ;
00038 PyObject *pN;
00039 double r2;
00040 int ccw;
00041 if (!PyArg_ParseTuple(args, "O!O!O!O!di",
00042 &(Base::VectorPy::Type), &pM1,
00043 &(Base::VectorPy::Type), &pP,
00044 &(Base::VectorPy::Type), &pQ,
00045 &(Base::VectorPy::Type), &pN,
00046 &r2, &ccw))
00047 return NULL;
00048
00049 Base::Vector3d M1 = Py::Vector(pM1, false).toVector();
00050 Base::Vector3d P = Py::Vector(pP, false).toVector();
00051 Base::Vector3d Q = Py::Vector(pQ, false).toVector();
00052 Base::Vector3d N = Py::Vector(pN, false).toVector();
00053
00054 Base::Vector3d u = Q - P;
00055 Base::Vector3d v = P - M1;
00056 Base::Vector3d b;
00057 if (ccw)
00058 b = u % N;
00059 else
00060 b = N % u;
00061 b.Normalize();
00062
00063 double uu = u * u;
00064 double uv = u * v;
00065 double r1 = v.Length();
00066
00067
00068 r2 *= Base::sgn(uv);
00069
00070 double cc = 2.0 * r2 * (b * v - r1);
00071 double d = uv * uv - uu * cc;
00072 if (d < 0) {
00073 PyErr_SetString(PyExc_Exception, "Unable to caluclate intersection points");
00074 return NULL;
00075 }
00076
00077 double t;
00078 double t1 = (-uv + sqrt(d)) / uu;
00079 double t2 = (-uv - sqrt(d)) / uu;
00080
00081 if (fabs(t1) < fabs(t2))
00082 t = t1;
00083 else
00084 t = t2;
00085
00086 Base::Vector3d M2 = P + (u*t) + (b*r2);
00087 Base::Vector3d S1 = (r2 * M1 + r1 * M2)/(r1+r2);
00088 Base::Vector3d S2 = M2 - (b*r2);
00089
00090 Py::Tuple tuple(3);
00091 tuple.setItem(0, Py::Vector(S1));
00092 tuple.setItem(1, Py::Vector(S2));
00093 tuple.setItem(2, Py::Vector(M2));
00094
00095 return Py::new_reference_to(tuple);
00096 }
00097
00098
00099 struct PyMethodDef PartDesign_methods[] = {
00100 {"makeFilletArc" ,makeFilletArc,METH_VARARGS,
00101 "makeFilletArc(...) -- Fillet arc."},
00102 {NULL, NULL}
00103 };