Hi, I would like to generate a set of N uniformly spaced points along a curve (of any type) between two points falling on that curve.
Any help is much appreciated.
Cheers, Chris
// INPUTS ARE:
curve_NPoints(Handle(Geom_Curve) curve1
Handle(Geom_CartesianPoint) point1
Handle(Geom_CartesianPoint) point2
int N // no. points to generate
// PROCESS:
// GET PARAMETERS OF TWO GIVEN POINTS ON CURVE
gp_Pnt pnt1 = point1->Pnt();
gp_Pnt pnt2 = point2->Pnt();
GeomAPI_ProjectPointOnCurve pntOnCurve1(pnt1, curve1);
GeomAPI_ProjectPointOnCurve pntOnCurve2(pnt2, curve1);
Standard_Real U1 = pntOnCurve1.LowerDistanceParameter();
Standard_Real U2 = pntOnCurve2.LowerDistanceParameter();
// GET DISTANCE BETWEEN TWO POINTS ON CURVE
GeomAdaptor_Curve curve1Adaptor(curve1);
GCPnts_AbscissaPoint abscissa1;
Standard_Real distance = abscissa1.Length(curve1Adaptor, U1, U2);
// SPACING FOR NEW POINTS
Standard_Real spacing;
if (U1 < U2)
{
spacing = distance / (N+1);
}
else if (U1 > U2)
{
spacing = -1 * distance / (N+1);
}
// CREATE POINTS AT REQUIRED SPACING, STARTING FROM POINT 1
TColgp_Array1OfPnt pntList(1, N);
Standard_Real U = U1;
gp_Pnt newPnt;
for (int i = 1; i <= N; i++)
{
GCPnts_AbscissaPoint abscissa2(curve1Adaptor, spacing, U);
U = abscissa2.Parameter();
newPnt = curve1Adaptor.Value(U);
pntList.SetValue(i, newPnt);
}
// RETURN LIST
I am reasonably new to Open Cascade (and also C++), so it might look a bit inefficient. Also, after writing this solution I realised there is a GCPnts_UniformAbscissa class for computing a uniform distribution of points on a curve .....
Wed, 04/15/2009 - 10:27
I think you should try: GCPnts_AbscissaPoint
Wed, 04/15/2009 - 12:36
Other suggestion:
BRepAdaptor_Curve Adaptor11(TopoDS::Edge(Ex11.Current()));
//cout<<"Curve type: "<
Thu, 04/16/2009 - 04:00
Thankyou for your suggestions. My solution is:
// INPUTS ARE:
curve_NPoints(Handle(Geom_Curve) curve1
Handle(Geom_CartesianPoint) point1
Handle(Geom_CartesianPoint) point2
int N // no. points to generate
// PROCESS:
// GET PARAMETERS OF TWO GIVEN POINTS ON CURVE
gp_Pnt pnt1 = point1->Pnt();
gp_Pnt pnt2 = point2->Pnt();
GeomAPI_ProjectPointOnCurve pntOnCurve1(pnt1, curve1);
GeomAPI_ProjectPointOnCurve pntOnCurve2(pnt2, curve1);
Standard_Real U1 = pntOnCurve1.LowerDistanceParameter();
Standard_Real U2 = pntOnCurve2.LowerDistanceParameter();
// GET DISTANCE BETWEEN TWO POINTS ON CURVE
GeomAdaptor_Curve curve1Adaptor(curve1);
GCPnts_AbscissaPoint abscissa1;
Standard_Real distance = abscissa1.Length(curve1Adaptor, U1, U2);
// SPACING FOR NEW POINTS
Standard_Real spacing;
if (U1 < U2)
{
spacing = distance / (N+1);
}
else if (U1 > U2)
{
spacing = -1 * distance / (N+1);
}
// CREATE POINTS AT REQUIRED SPACING, STARTING FROM POINT 1
TColgp_Array1OfPnt pntList(1, N);
Standard_Real U = U1;
gp_Pnt newPnt;
for (int i = 1; i <= N; i++)
{
GCPnts_AbscissaPoint abscissa2(curve1Adaptor, spacing, U);
U = abscissa2.Parameter();
newPnt = curve1Adaptor.Value(U);
pntList.SetValue(i, newPnt);
}
// RETURN LIST
I am reasonably new to Open Cascade (and also C++), so it might look a bit inefficient. Also, after writing this solution I realised there is a GCPnts_UniformAbscissa class for computing a uniform distribution of points on a curve .....
Thanks again for your help.
Chris