Line tangent to 3d curve at point

Hi,

How can I find the tangent of a 3d curve at a point?
Like this http://upload.wikimedia.org/wikipedia/commons/2/2d/Bezier_2_big.gif
GeomAPI_Interpolate seems promising

thanks

Mauro Mariotti's picture

To have a tangent vector at a given parameter:
Geom_Curve::D1

To have the tangent unit vector:
GeomLProp_CLProps::Tangent

Regards.
Mauro

Daniel Park's picture

Hi Mauro,

How can I use this to draw a line?

thanks Daniel

Mauro Mariotti's picture

To create an infinite tangent line, create a Geom_Line with the point and direction computed as said before.
If you need a finite one, create a Geom_TrimmedCurve from it.

Ciao.
Mauro

AP's picture

if you have a topoDS_Edge of a curve.

double parameter = 0.1;
gp_Pnt p1 = PointonCurve(curve,parameter);
gp_Vec v1 = getVectorTangentToCurveAtPoint(curve,parameter);
TopoDS_Shape l1 = Lineptdir(p1,v1,0,100)

use the following functions to get the point and vector at parameter.

They are extracts from the openshapefactory project.

https://code.google.com/p/openshapefactory/source/browse/SFMQTDLL/src/sr...

const gp_Vec& getVectorTangentToCurveAtPoint(TopoDS_Shape SupportEdge, Standard_Real uRatio)
{
if(SupportEdge.IsNull()) qDebug() << "supportedge null";
const TopoDS_Edge& aEdge = TopoDS::Edge (SupportEdge);
Standard_Real aFP, aLP, aP;
Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFP, aLP);
aP = aFP + (aLP - aFP) * uRatio;
gp_Vec& V1 = gp_Vec() ;
gp_Pnt p1;
aCurve->D1(aP,p1,V1);

return V1;

}

TopoDS_Edge Lineptdir(gp_Pnt origin, gp_Vec dir, double length1, double length2)
{

Handle(Geom_Curve) spinaxis = new Geom_Line (origin,dir);
spinaxis = new Geom_TrimmedCurve (spinaxis, length1, length2);
double fp = spinaxis->FirstParameter();
double ep = spinaxis->LastParameter();

TopoDS_Edge Result = BRepBuilderAPI_MakeEdge(spinaxis,fp,ep);

return Result;

}

const gp_Pnt& PointonCurve(TopoDS_Shape SupportEdge, Standard_Real uRatio)

{
gp_Pnt p1;
if (SupportEdge.IsNull())
{
return p1;
}
const TopoDS_Edge& aEdge = TopoDS::Edge (SupportEdge);
Standard_Real aFP, aLP, aP;
Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFP, aLP);
aP = aFP + (aLP - aFP) * uRatio;
p1 = aCurve->Value(aP);

return p1;
}

Daniel Duesentrieb's picture

exactly what I was looking for. Thanks for sharing!