# Arc direction

Hi all,
How do I find out the arc direction clockwise or counterclockwise ?

``````> CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
> {
> 	CRhinoGetObject get_curve;
> 	get_curve.EnablePreSelect(false);
> 	get_curve.EnableGroupSelect(TRUE);
> 	get_curve.SetCommandPrompt(L"Slect curves");
> 	get_curve.SetGeometryFilter(CRhinoGetObject::curve_object);
> 	for (int i = 0; i < go.ObjectCount(); i++)
> 	{
> 		const CRhinoObjRef& ref_curve = get_curve.Object(i);
> 		const CRhinoObject* get_curve = ref_curve.Object();
> 		const ON_ArcCurve* arc = ON_ArcCurve::Cast(get_curve->Geometry());
> 			if (arc->IsArc()) {
> 				ON_3dPoint pts = arc->PointAtStart();
> 				ON_3dPoint pte = arc->PointAtEnd();
> 				ON_3dPoint ptc = arc->m_arc.Center();
> 				............
> 				............
> 				............
> 			}
>		 }
> 	return CRhinoCommand::success;
> }
``````

– Karlos

Hi @ccx07,

The direction of an arc curve is counter-clockwise in relation to the plane on which it lies. The starting point of an arc curve alway lies on the arc plane’s x-axis.

– Dale

Can I give you a small example.Thank You Dale.

– Karlos

If the curve may have been flipped, then you can get the center point of the Arc, and then calculate the Plane Normal (or CrossProduct) based on the the StartPt and EndPt (and Center) of the Arc. The direction of the Normal will then imply the direction of the Arc.

If you already know the Plane and no flipping of the curve has happened, then you know the direction of the Arc (CCW).

If you prefer going to the other side of the river to get some water then compare the angles between StartPt and EndPt of the arc relative to the Arc Center. The angles:

• `VectorAngle((StartPt-C) > (EndPt-C)) = CCW` and
• `VectorAngle((StartPt-C) < (EndPt-C)) = CW`

I didn’t test this, though…

// Rolf

1 Like

Hi @ccx07,

If your curve lies in the world xy plane, then:

``````if (arccurve.m_arc.Normal() > 0)
ccw = 1; // true
``````

Otherwise, calculate the dot product of the arc curve’s normal and the construction plane’s normal.

``````double dot = ON_DotProduct(arccurve.m_arc.Normal(), cplane.Normal());
if (dot > 0.0)
ccw = 1; // true
else if (dot < 0.0)
ccw = 0; // false (cw)
else
ccw = -1; // unknown
``````

There is also `ON_ClosedCurveOrientation`. see opennurbs_curve.h for details.

– Dale

1 Like

Thank you very much Dale, Rolf.
– Karlos