Orientation Curve No Closed


#1

Hello.

I´m programming a project with C# and rhinho

I want to know the orientation of a curve when this curve is not closed.

Thank you.


(Menno Deij - van Rijswijk) #2

When you have a Curve object, you can ask for PointAtStart and PointAtEnd.
This can give an idea of the orientation of the curve.

Also, you can ask for TangentAt(t) where t is in the curve domain. This is a tangent vector that is oriented “in the direction of the curve”.

Curve crv;
Point3d startPoint = crv.PointAtStart;
Point3d endPoint = crv.PointAtEnd;

double t = crv.Domain.Mid;
Vector3d midCurveTangent = crv.TangentAt(t);


#3

Can I know if the orientation is Clockwise or CounterClockwise?

When the curve is closed I use this:

CurveOrientation orientation = curva.ClosedCurveOrientation(plano);
if (orientation == CurveOrientation.Clockwise)
    ....
else
   ...

(Menno Deij - van Rijswijk) #4

No. You could temporarily close the curve if that makes any sense in your case.

Curve open; // defined elsewhere
PolyCurve closed = new PolyCurve();
closed.Append(open);
closed.Append(new LineCurve(closed.PointAtEnd, closed.PointAtStart));
CurveOrientation o = closed.ClosedCurveOrientation(plano);

#5

Hi,

I’ve the same problem, but I want to get the orientation of line.

I’ve modify the menno algotirhm adding a intermide line, else I can’t get the orientation

        Curve open = (Curve)curva.Duplicate(); // defined elsewhere

PolyCurve closed = new PolyCurve();
            closed.Append(open);
            Point3d ptoIntermedio = closed.PointAtEnd;
            ptoIntermedio.Z += 5;
            closed.Append(new LineCurve(closed.PointAtEnd, ptoIntermedio));
            closed.Append(new LineCurve(ptoIntermedio, closed.PointAtStart));
            closed.TryGetPlane(out plano);
            CurveOrientation orientacionCurva = closed.ClosedCurveOrientation(plano);

if ( orientacionCurva != orientacion)
                curva.Reverse();

But the code is ugly… there is a better algotirhm to set the orientation?


(Dale Fugier) #6

A line does not have a clockwise/counter-clockwise orientation. But a line does have a direction.

Rhino.Geometry.Vector3d dir = line.To - line.From;

You can compare this vector to whatever to determine its orientation…


#7

Ok.

I need the orientation because I want import from a dxf that contains lines and structure of model, and I’ve to build a model from this lines.

As the dxf only are curves, I always need set the same direction to obtain always the same point start and point end to build the model. If the direction is inverted the model isn’t built well


(Menno Deij - van Rijswijk) #8

To see if two curves are “more or less traveling in the same direction”, use Curve.DoDirectionsMatch
Maybe it is useful?

See http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_Geometry_Curve_DoDirectionsMatch.htm