arc direction from start to end point?

arc direction from start to end point?

MattWynn
Alumni Alumni
1,800 Views
8 Replies
Message 1 of 9

arc direction from start to end point?

MattWynn
Alumni
Alumni

Fusion SketchArc has start point, centerpoint, end point...  Does anyone have a way to know if the arc goes clockwise or counter-clockwise from start to end? I have simple examples where it seems to go either way... 


Matt Wynn
Senior Manager, Software Development, Fusion Fabrication
0 Likes
Accepted solutions (1)
1,801 Views
8 Replies
Replies (8)
Message 2 of 9

marshaltu
Autodesk
Autodesk

Hello,

 

In Fusion 360 UI, you can create arc by either clockwise or counter-clockwise. It depends on the hint direction which mouse gives. 

 

In Fusion 360 API, we provides the method "SketchArcs.addByCenterStartSweep(centerPoint, startPoint, sweepAngle)" to create arc. The sweep angle is defined in radians and a positive value defines counter-clockwise sweep. 

 

If the API behaviour you saw was different, it would be great if you can provide your sample codes for investigation.

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 3 of 9

ekinsb
Alumni
Alumni

I just did some simple tests and no matter how I drew the arc, the resulting created arc is always drawn CCW.  Can you post an example that shows otherwise?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 4 of 9

MattWynn
Alumni
Alumni

@marshaltu, I'm asking about getting sketch arc geometry, not creating it.

 

I have this for creating X,Y,I (I = point type, end, CCW center, CW center) arrays from sketch arc (C++):

 

Ptr<SketchPoint> p1 = arc->startSketchPoint();
Ptr<SketchPoint> p2 = arc->endSketchPoint();
Ptr<SketchPoint> center = arc->centerSketchPoint();
xValues.push_back(p1->geometry().get()->x()*10.0); yValues.push_back(p1->geometry().get()->y()*10.0); iCodes.push_back(0);
/*arc-> CW or CCW? */
xValues.push_back(center->geometry().get()->x()*10.0); yValues.push_back(center->geometry().get()->y()*10.0); iCodes.push_back(1);
xValues.push_back(p2->geometry().get()->x()*10.0); yValues.push_back(p2->geometry().get()->y()*10.0); iCodes.push_back(10);

 

@ekinsb, I have a simple sketch with 4 arcs that I was getting inconsistent results with (after downstream processing).  I will examine in more detail (assuming CCW), and post my findings.

 

Thanks very much!


Matt Wynn
Senior Manager, Software Development, Fusion Fabrication
0 Likes
Message 5 of 9

MattWynn
Alumni
Alumni

See attached Shape 5 clockwise arcs.f3d, two lines connected to two semicircles.

 

shape 5 clockwise arcs.png

 

 

With this C++ code:

 

Ptr<SketchCurves> curves = _Sketch->sketchCurves();

// lines
Ptr<SketchLines> lines = curves->sketchLines();
for (size_t i = 0; i < lines->count(); i++)
{
Ptr<SketchLine> line = lines->item(i);

Ptr<SketchPoint> p1 = line->startSketchPoint();
Ptr<SketchPoint> p2 = line->endSketchPoint();

#ifdef _WIN32
char sMsg[1024] = "";
sprintf_s(sMsg, "Sketch Line Start Point ( %lg, %lg, %lg )\n", p1->geometry().get()->x()*10.0, p1->geometry().get()->y()*10.0, p1->geometry().get()->z()*10.0);
OutputDebugStringA(sMsg);
sprintf_s(sMsg, "Sketch Line End Point ( %lg, %lg, %lg )\n", p2->geometry().get()->x()*10.0, p2->geometry().get()->y()*10.0, p2->geometry().get()->z()*10.0);
OutputDebugStringA(sMsg);
#endif
}

// arcs
Ptr<SketchArcs> arcs = curves->sketchArcs();
for (size_t i = 0; i < arcs->count(); i++)
{
Ptr<SketchArc> arc = arcs->item(i);

Ptr<SketchPoint> p1 = arc->startSketchPoint();
Ptr<SketchPoint> p2 = arc->endSketchPoint();
Ptr<SketchPoint> center = arc->centerSketchPoint();

#ifdef _WIN32
char sMsg[1024] = "";
sprintf_s(sMsg, "Sketch Arc Start Point ( %lg, %lg, %lg )\n", p1->geometry().get()->x()*10.0, p1->geometry().get()->y()*10.0, p1->geometry().get()->z()*10.0);
OutputDebugStringA(sMsg);
sprintf_s(sMsg, "Sketch Arc Centr Point ( %lg, %lg, %lg )\n", center->geometry().get()->x()*10.0, center->geometry().get()->y()*10.0, center->geometry().get()->z()*10.0);
OutputDebugStringA(sMsg);
sprintf_s(sMsg, "Sketch Arc End Point ( %lg, %lg, %lg )\n", p2->geometry().get()->x()*10.0, p2->geometry().get()->y()*10.0, p2->geometry().get()->z()*10.0);
OutputDebugStringA(sMsg);
#endif

}

 

I get this result:

 

Sketch Line Start Point ( 50.7542, -236.576, 0 )
Sketch Line End Point ( 50.7542, -150.606, 0 )
Sketch Line Start Point ( 81.9296, -150.606, 0 )
Sketch Line End Point ( 81.9296, -236.576, 0 )
Sketch Arc Start Point ( 50.7542, -150.606, 0 )
Sketch Arc Centr Point ( 66.3419, -150.606, 0 )
Sketch Arc End Point ( 81.9296, -150.606, 0 )
Sketch Arc Start Point ( 81.9296, -236.576, 0 )
Sketch Arc Centr Point ( 66.3419, -236.576, 0 )
Sketch Arc End Point ( 50.7542, -236.576, 0 )

 

 

Looks clockwise to me but perhaps I have made a mistake somewhere...

 

I do have other examples, that came from the same source, but this is the simplest geometry.  Some arcs are CW, some are CCW.

 

 


Matt Wynn
Senior Manager, Software Development, Fusion Fabrication
0 Likes
Message 6 of 9

MattWynn
Alumni
Alumni

try attach f3d file again...


Matt Wynn
Senior Manager, Software Development, Fusion Fabrication
0 Likes
Message 7 of 9

MattWynn
Alumni
Alumni

shape 6 has inconsistent arcs, outside they are CCW, inside is CW

 

shape 6 inconsistent arcs.png

 

interpreted as 

shape 6 exported.png

 


Matt Wynn
Senior Manager, Software Development, Fusion Fabrication
0 Likes
Message 8 of 9

ekinsb
Alumni
Alumni
Accepted solution

I'm able to reproduce what you're seeing when I use the models you provided.  Are they imported from something else or did you draw them in Fusion?  If they're drawn in Fusion, I'm curious how you did it.

 

Regardless of how it was built, the result you're seeing is not because arcs are CCW or CW, because they're always CCW, but is because sketch geometry is 3D and the normal of the arcs that have the problem is negative Z, whereas all of the arcs I've created it's positive Z.  You can't think of it as looking at the "back" of the arc.  When you do that the direction will appear reversed.  If you're reading sketch geometry out of Fusion, you probably want to first check if everything lies on the X-Y plane.  You can do that by using the is2D property on the sketch geometry.  For arcs, you'll need to check the normal property to see if it is positive or negative Z and account for that.

 

-Brian


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 9 of 9

MattWynn
Alumni
Alumni

The parts were imported from Inventor part files on Dec 7, 2015.

 

I've added 

 

Ptr<Vector3D> normVector = arc->geometry()->normal();
Ptr<Vector3D> zVector = Vector3D::create(0.0, 0.0, 1.0);
double dotProd = normVector->dotProduct(zVector);

bool CCW = dotProd > 0.0 ? true : false;

 

and now my results are consistent.

 

THANKS!  I learned a lot.

 

And of my arcs are not 2D, I'm now using evaluator to get the strokes.  This should work great.

 


Matt Wynn
Senior Manager, Software Development, Fusion Fabrication
0 Likes