Sketch Inside/Outside Curve

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Sketch Inside/Outside Curve

Post by keithsloan52 »

I am trying to do some processing on a sketch, when scanning a sketches geometry is there an easy way of determining if a curve is an inside or outside curve?
see screenshot
Sketch.jpg
Sketch.jpg (26.49 KiB) Viewed 2198 times
Last edited by keithsloan52 on Mon Dec 06, 2021 1:50 pm, edited 2 times in total.
User avatar
Shalmeneser
Veteran
Posts: 9475
Joined: Wed Dec 23, 2020 12:04 am
Location: Fr

Re: Sketch Inside/Outside Curve

Post by Shalmeneser »

Coming from outside, each time you cross a line, change color (B/W).
If the center is the same color of outside area : outside.
If ...

but center of inside curve can be in the outside area.
Attachments
Capture du 2021-12-03 00-06-58.png
Capture du 2021-12-03 00-06-58.png (3.77 KiB) Viewed 2126 times
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Sketch Inside/Outside Curve

Post by openBrain »

Shalmeneser wrote: Thu Dec 02, 2021 11:05 pm Coming from outside, each time you cross a line, change color (B/W).
If the center is the same color of outside area : outside.
If ...

but center of inside curve can be in the outside area.
I guess the question is concave/convex ;)
User avatar
Shalmeneser
Veteran
Posts: 9475
Joined: Wed Dec 23, 2020 12:04 am
Location: Fr

Re: Sketch Inside/Outside Curve

Post by Shalmeneser »

Find upper-left point then turn clockwise along the border. One side is inside, other side is outside.
chrisb
Veteran
Posts: 53924
Joined: Tue Mar 17, 2015 9:14 am

Re: Sketch Inside/Outside Curve

Post by chrisb »

openBrain wrote: Fri Dec 03, 2021 8:18 am I guess the question is concave/convex ;)
No, it works with these as well. It is only critical if you by a bad coincidence cross a border at a point on the curve to be tested. Starting from the outside count the border trsnsitions. If the number is odd you are inside, if it is even, you are outside. Herer is a rough example using Sketcher
red: Sketch to be tested
white: outside
blue: inside.
Attachments
SnipScreenshot-9487a0.png
SnipScreenshot-9487a0.png (35.92 KiB) Viewed 2034 times
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Sketch Inside/Outside Curve

Post by openBrain »

chrisb wrote: Fri Dec 03, 2021 9:30 am No, it works with these as well. It is only critical if you by a bad coincidence cross a border at a point on the curve to be tested. Starting from the outside count the border trsnsitions. If the number is odd you are inside, if it is even, you are outside. Herer is a rough example using Sketcher
red: Sketch to be tested
I know this :) My point is that I guess that OP question is actually to be able to determine if a curve is concave or convex. ;)
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Sketch Inside/Outside Curve

Post by keithsloan52 »

openBrain wrote: Fri Dec 03, 2021 9:34 am
chrisb wrote: Fri Dec 03, 2021 9:30 am No, it works with these as well. It is only critical if you by a bad coincidence cross a border at a point on the curve to be tested. Starting from the outside count the border trsnsitions. If the number is odd you are inside, if it is even, you are outside. Herer is a rough example using Sketcher
red: Sketch to be tested
I know this :) My point is that I guess that OP question is actually to be able to determine if a curve is concave or convex. ;)
The OP wants to be able to determine from the information available from scanning the sketch.
I know the theory about does it cross a line etc, but how to program it?

To help me understand what my options are the code that scans the sketch has

Code: Select all

if case('Part::GeomArcOfCircle') :
              print('ArcofCircle')
              print(dir(gs))
              print(gs.StartPoint)
              print(gs.EndPoint)
              print(gs.Center)
              print(gs.Radius)
              print(gs.centerOfCurvature)
              print(gs.curvature)
              print(gs)
Which outputs

Code: Select all

09:51:40  ArcofCircle
09:51:40  ['AngleXU', 'Axis', 'Center', 'Circle', 'Content', 'Continuity', 'EndPoint', 'FirstParameter', 'LastParameter', 'Location', 'MemSize', 'Module', 'Radius', 'Rotation', 'StartPoint', 'Tag', 'TypeId', 'XAxis', 'YAxis', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'approximateBSpline', 'centerOfCurvature', 'clone', 'continuityWith', 'copy', 'curvature', 'deleteExtensionOfName', 'deleteExtensionOfType', 'discretize', 'dumpContent', 'getAllDerivedFrom', 'getD0', 'getD1', 'getD2', 'getD3', 'getDN', 'getExtensionOfName', 'getExtensionOfType', 'getExtensions', 'hasExtensionOfName', 'hasExtensionOfType', 'intersect', 'intersect2d', 'intersectCC', 'intersectCS', 'isClosed', 'isDerivedFrom', 'isPeriodic', 'length', 'makeRuledSurface', 'mirror', 'normal', 'parameter', 'parameterAtDistance', 'period', 'restoreContent', 'reverse', 'reversedParameter', 'rotate', 'scale', 'setExtension', 'setParameterRange', 'tangent', 'toBSpline', 'toNurbs', 'toShape', 'transform', 'translate', 'trim', 'value']
09:51:40  Vector (6.171572889881885, 2.4369546850601067e-16, 0.0)
09:51:40  Vector (11.999999999999998, -0.999999999972443, 0.0)
09:51:40  Vector (9.171572889881885, 4.14020057e-08, 0.0)
09:51:40  3.0
09:51:40  <built-in method centerOfCurvature of Part.ArcOfCircle object at 0x7fed22754de8>
09:51:40  <built-in method curvature of Part.ArcOfCircle object at 0x7fed22754de8>
Also would somebody remind me of how to obtain the parameters that can be passed to a function i.e approximateBSpline?
Also on the bases that one has to perform an algorithm on line crossing etc what do the various intersect?? functions do?
What does the function curvature return?
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Sketch Inside/Outside Curve

Post by Roy_043 »

For the outer wire this can work:
Create a face from the sketch: face = Part.makeFace(sketch.Shape, "Part::FaceMakerSimple").
Get an ordered_vertexes_list: face.OuterWire.OrderedVertexes.
For each arc check the order of edge.firstVertex() and edge.lastVertex() in ordered_vertexes_list.
If the order is first->last the arc is convex.

To check if a point is inside the face you can use its isInside() method.
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: Sketch Inside/Outside Curve

Post by paullee »

Interesting topic and @Roy_043's approach to problem to read :)

@Roy_043 indicates the solution apply to outerwire. Just some random thoughts. Sketch.Shape.Wires should return all wires in a Sketch e.g.

Code: Select all

>>> s.Shape.Wires
[<Wire object at 0x557e08a1ef10>, <Wire object at 0x557e08a18f90>, <Wire object at 0x557e08a19010>]
Test if the wire one by one if it is closed; then test the wires if they are 'inside' or 'outside' against the outerwire ( pick a point along the wire and test by algorithm discussed above?). Then test the concerned curve with @Roy_043's approach - but the reverse of the logic is true?

https://towardsdatascience.com/is-the-p ... 4b86472119
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Sketch Inside/Outside Curve

Post by onekk »

Something similar to some modelling discussion on this page:

https://dev.opencascade.org/doc/occt-7. ... algos.html

when dealing with Interior/Exterior and following

It seems that OCCT has some methods (functions in C++ ??) to deal with them, but I don't know if and how they are implemented in FreeCAD.

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/
Post Reply