in which sequence does FreeCAD stores an arc in the Sketcher: anti-clockwise or indifferent or...

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
JohnB3
Posts: 17
Joined: Sat Feb 06, 2021 3:08 pm

in which sequence does FreeCAD stores an arc in the Sketcher: anti-clockwise or indifferent or...

Post by JohnB3 »

Hi community,

I have a question about "in which sequence does FreeCAD stores an arc in the Sketcher: anti-clockwise or indifferent or...".

For mechanical calculations, I export the fundamental sketch geometry to a datafile. This datafile is the import dat file for my mechanical calculation programme.
For this, I select the sketch geometry by mouse. Basic code (using using Gui.Selection) : "sels=FreeCADGui.Selection.getSelectionEx() , selectedEdge=sels[0].SubObjects.copy()" and with "points=selectedEdge.discretize(numberOfPoints)" for getting 3 points to distinguish "line", "circle", "point" and "arc". Also for deriving the essential information such like endpoints, midpoint, radius, length.

According to my observations, the data of an arc is stored anti-clockwise. So, if I select the arc by mouse, the two end points are stored in anti-clockwise direction in my datafile. For my mechanical calculations, outside FreeCAD, this is not very handy, because the joint connection between the "mechanical elements" might get lost in my datafile. I have to sort out my pivot points in the datafile afterwards, or I only should select points in the correct sequence instead of the elementary geometry "lines, arcs".

1. Are my observations correct? Will arcs always generate points in anti-clockwise direction by using Are arcs really stored anti-clockwise, always?
2. Is it possible to let FreeCAD know at what side the arc is selected as possible solution? (Of course I can introduce Points as connection points..)

Hope, that someone knows an answer. Thank you very much.

Best regards,
John.

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.4 (GitTag)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: 980bf9060e28555fecd9e3462f68ca74007b70f8
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: in which sequence does FreeCAD stores an arc in the Sketcher: anti-clockwise or indifferent or...

Post by paullee »

JohnB3 wrote: Wed May 26, 2021 9:12 am I have a question about "in which sequence does FreeCAD stores an arc in the Sketcher: anti-clockwise or indifferent or...".
I do not have a definite answer, just some experience and share my memory below, hope somebody can provide you more solid answer.

First, it may depend whether you are talking about 'Edit' mode of the Sketch or not.

I remember all 'arc' in Edit mode are 'interpreted' as anti-clockwise. But the Arc in Wire / Edge 'outside' Edit model may not be.

Seems once dig into a post by @DeepSOIC had discussed something about the topology in OCC (OpenCascade kernel).
User avatar
onekk
Veteran
Posts: 6208
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: in which sequence does FreeCAD stores an arc in the Sketcher: anti-clockwise or indifferent or...

Post by onekk »

I doubt that it is possible to change the "direction" of the arc, as the "internal representation" rely on the "trigonometric convention", so the circle and arcs are calculated anticlockwise, I'm not 100% sure for Sketcher, but the "primitive" is generated by OCCT (modeling engine of FreeCAD).

As you create sketcher geometry, the point are coincident, so if you export 3 point for the arc, you could draw it in whatever way you want in the destination program.

This image show to circle obtained using Part.ArcOfCircle(circle, start_angle, end_angle)
discretize.png
discretize.png (6.1 KiB) Viewed 2152 times

originating circle is the same:

- first circle (unmarked points) was generated using:

Code: Select all

h_cir = Part.ArcOfCircle(cir, math.pi , 0)
to draw the "lower part of circle", you will se the arrow showing the start point and end point of the discretized shape (16 points)

- second circle (with c2 as suffix of proints) was generated using:

Code: Select all

h_cir2 = Part.ArcOfCircle(cir, 0, math.pi)
And is shown as the upper part of the circle

Note the inversion of the start and ending point and the relative inversion of the coordinates of the start and end point of the discretized curve, respecting the order of the creation

Hope it helps

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
JohnB3
Posts: 17
Joined: Sat Feb 06, 2021 3:08 pm

Re: in which sequence does FreeCAD stores an arc in the Sketcher: anti-clockwise or indifferent or...

Post by JohnB3 »

Summarized, as far as we have all observed, the arc is created anti-clockwise. Hence, I have to find out another method.Now I'm thinking of "double click" at the "side of the start" while selecting. Of course, I have to solve the "de-selection" in that case. Also tricks like "an extra node" or "users input input("what side") are candidates for solving the inconveniences.
Thank you for your input.
In my view, we may close this submission. Thank very much. John.
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: in which sequence does FreeCAD stores an arc in the Sketcher: anti-clockwise or indifferent or...

Post by paullee »

JohnB3 wrote: Wed May 26, 2021 5:03 pm Ping

The mentioned post, hope it is related :)

Sketch: how to handle reversed external arcs?
JohnB3
Posts: 17
Joined: Sat Feb 06, 2021 3:08 pm

Re: in which sequence does FreeCAD stores an arc in the Sketcher: anti-clockwise or indifferent or...

Post by JohnB3 »

Yes, very much! The mechanism is explained in that post. I learned that in most cases (but not always and when not ) the direction is counter clock wise. And probably, the post also described the solution for me.
I''m able to check the direction of the arc. In fact, I already use the direction in my code. I needed the direction for calculated the positioning of the center of the arc. So, if the selected direction is not according to the wanted selection order, I can change the selection direction in my relevant code.
Thank you very much for drawing my attention to that topic.
John.
User avatar
onekk
Veteran
Posts: 6208
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: in which sequence does FreeCAD stores an arc in the Sketcher: anti-clockwise or indifferent or...

Post by onekk »

It depends you have not to calculate the center of the arc, the arc as geometric object has the centre as property it is here as it has the starting and the ending point and also radius.

If not how it could be drawn?

It's a matter of inspect object properties.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
JohnB3
Posts: 17
Joined: Sat Feb 06, 2021 3:08 pm

Re: in which sequence does FreeCAD stores an arc in the Sketcher: anti-clockwise or indifferent or...

Post by JohnB3 »

:D I Hi Carlo. Yes, you'r right. That should be the right way. But I'm not a python engineer. I'm still learning. And this forum and the FreeCAD manual are very important for me. I tried , but it didn't worked out. So, I created my own math to do the work.
User avatar
onekk
Veteran
Posts: 6208
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: in which sequence does FreeCAD stores an arc in the Sketcher: anti-clockwise or indifferent or...

Post by onekk »

speaking of circular arcs in XY plane is not difficult to calculate points, I suppose that if you use sketcher you draw in 2d and in XY.

Now I don't know very well sketcher scripting as I model mostly with Part and some Draft methods, but if you have an edge derived from a circle it's a mere writing exercise.

Code: Select all


obj = arc.Curve
cent = obj.Center
rad = obj.Radius

Plus obviously the start point and endpoint.

With some code it will be more easy .

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
JohnB3
Posts: 17
Joined: Sat Feb 06, 2021 3:08 pm

Re: in which sequence does FreeCAD stores an arc in the Sketcher: anti-clockwise or indifferent or...

Post by JohnB3 »

Hi Carlo. I don't know how to get it when working in the sketcher. I always get non-information. Or "no such attribute".

sels=FreeCADGui.Selection.getSelectionEx()
print("selection", sels[0].SubObjects[0])

Results in:
selection <Edge object at 00000207DBF9CDC0>
Post Reply