Fri, 02/27/2009 - 15:37

Forums:

Hi, is it possible to find middle point of an edge considering its total length instead of parameters?

Thanks

Fri, 02/27/2009 - 15:37

Forums:

Hi, is it possible to find middle point of an edge considering its total length instead of parameters?

Thanks

Fri, 02/27/2009 - 16:06

I don't know the best way, but I do have a couple of suggestions you could try:

- You could try using GCPnts_UniformAbscissa to either generate 3 points or use an abscissa of 1/2 the arc length.

- You could compute 1/2 the arc length and compute the parameter of the midpoint using a weighted binary search like algorithm

In case you are not aware, you can use BRepGProp::LinearProperties to compute the length of an edge.

Fri, 02/27/2009 - 19:02

An exception raises with the code below:

Handle(Geom_Curve) aCurve = BRep_Tool::Curve(edge,u,v);

Adaptor3d_Curve adaptor = (Adaptor3d_Curve) GeomAdaptor_Curve(aCurve);

GCPoints_UniformAbscissa abscissa(adaptor, nbPoints); // exception here

Where is my mistake here, do I get the adaptor wrong?

Thanks again

Mon, 03/02/2009 - 10:28

I don't understand the second line of the source well.

Simply, the following will work.

GeomAdaptor_Curve adaptor( aCurve )

Mon, 03/02/2009 - 10:43

About the length of Edge, I needed it the other day, so I examined a little.

a) How to calclate the length of curve

Handle(Geom_Curve) aCurve = ...;

GeomAdaptor_Curve c(aCurve );

len = GCPnts_AbscissaPoint::Length( c );

b) How to calculate the parameter at specified distance from the position ts,

GCPnts_AbscissaPoint calc( c, dist, ts );

if ( calc.IsDone() ) {

ti = calc.Parameter();

}

c) if you specify the second parameter of BRepAdaptor_CompCurve true, parameter is measured as distance.

BRepAdaptor_CompCurve c(TopoDS::Wire(aShape), Standard_True );

gp_Pnt pm = c.Value( (c.FirstParameter() + c.LastParameter())/2.0 );

TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex( pm );

Good luck!

Mon, 03/02/2009 - 12:53

I tried a) and b) and both works perfect except when the curve is line, I think parameters are infinite at that case. How can I fix it?

Thanks again

Mon, 03/02/2009 - 13:25

Sorry not parameters, length was infinite and GProp_GProps::Mass() works well for lines so everthing works fine now, thanks.