Skip to content

Commit

Permalink
expose methods to Python to get normal, curvature and center of curva…
Browse files Browse the repository at this point in the history
…ture for curve
  • Loading branch information
wwmayer committed Oct 28, 2016
1 parent b59bbff commit 9cbcb36
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Mod/Part/App/GeometryCurvePy.xml
Expand Up @@ -95,6 +95,21 @@ parameterAtDistance([abscissa, startingParameter]) -> Float the</UserDocu>
of the nearest orthogonal projection of the point.</UserDocu>
</Documentation>
</Methode>
<Methode Name="normal" Const="true">
<Documentation>
<UserDocu>Vector = normal(pos) - Get the normal vector at the given parameter [First|Last] if defined</UserDocu>
</Documentation>
</Methode>
<Methode Name="curvature" Const="true">
<Documentation>
<UserDocu>Float = curvature(pos) - Get the curvature at the given parameter [First|Last] if defined</UserDocu>
</Documentation>
</Methode>
<Methode Name="centerOfCurvature" Const="true">
<Documentation>
<UserDocu>Vector = centerOfCurvature(float pos) - Get the center of curvature at the given parameter [First|Last] if defined</UserDocu>
</Documentation>
</Methode>
<Methode Name="intersect" Const="true">
<Documentation>
<UserDocu>
Expand Down
76 changes: 75 additions & 1 deletion src/Mod/Part/App/GeometryCurvePyImp.cpp
Expand Up @@ -383,7 +383,7 @@ PyObject* GeometryCurvePy::tangent(PyObject *args)
return 0;
gp_Dir dir;
Py::Tuple tuple(1);
GeomLProp_CLProps prop(c,u,1,Precision::Confusion());
GeomLProp_CLProps prop(c,u,2,Precision::Confusion());
if (prop.IsTangentDefined()) {
prop.Tangent(dir);
tuple.setItem(0, Py::Vector(Base::Vector3d(dir.X(),dir.Y(),dir.Z())));
Expand All @@ -402,6 +402,80 @@ PyObject* GeometryCurvePy::tangent(PyObject *args)
return 0;
}

PyObject* GeometryCurvePy::normal(PyObject *args)
{
Handle_Geom_Geometry g = getGeometryPtr()->handle();
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g);
try {
if (!c.IsNull()) {
double u;
if (!PyArg_ParseTuple(args, "d", &u))
return 0;
gp_Dir dir;
GeomLProp_CLProps prop(c,u,2,Precision::Confusion());
prop.Normal(dir);
return new Base::VectorPy(new Base::Vector3d(dir.X(),dir.Y(),dir.Z()));
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
return 0;
}

PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve");
return 0;
}

PyObject* GeometryCurvePy::curvature(PyObject *args)
{
Handle_Geom_Geometry g = getGeometryPtr()->handle();
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g);
try {
if (!c.IsNull()) {
double u;
if (!PyArg_ParseTuple(args, "d", &u))
return 0;
GeomLProp_CLProps prop(c,u,2,Precision::Confusion());
double C = prop.Curvature();
return Py::new_reference_to(Py::Float(C));
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
return 0;
}

PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve");
return 0;
}

PyObject* GeometryCurvePy::centerOfCurvature(PyObject *args)
{
Handle_Geom_Geometry g = getGeometryPtr()->handle();
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g);
try {
if (!c.IsNull()) {
double u;
if (!PyArg_ParseTuple(args, "d", &u))
return 0;
GeomLProp_CLProps prop(c,u,2,Precision::Confusion());
gp_Pnt V ;
prop.CentreOfCurvature(V);
return new Base::VectorPy(new Base::Vector3d(V.X(),V.Y(),V.Z()));
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
return 0;
}

PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve");
return 0;
}

PyObject* GeometryCurvePy::parameter(PyObject *args)
{
Handle_Geom_Geometry g = getGeometryPtr()->handle();
Expand Down

0 comments on commit 9cbcb36

Please sign in to comment.