expose methods to Python to get normal, curvature and center of curvature for curve

This commit is contained in:
wmayer 2016-10-28 21:19:27 +02:00
parent b59bbfffec
commit 9cbcb36280
2 changed files with 90 additions and 1 deletions

View File

@ -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>

View File

@ -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())));
@ -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();