[Solved] Help wih arc

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Help wih arc

Post by jfc4120 »

@onekk thanks for answers. But also using this code:

Code: Select all

zaxis = App.Vector(0, 0, 1)
p1 = App.Vector(0, TCLRD + WD, 0)
place1 = App.Placement(p1, App.Rotation(zaxis, 0))
circle1 = Draft.make_circle(TCLRD, placement=place1, face=None, startangle=270 - ELDG, endangle=270, support=None)
And that is using the example in the documentation.

Is there a way to get the begin point and end point of that arc? Or do I have to use part library or what. Seems there should be a way.

Remember I an new to python, and freecad, and trying to learn some simple stuff first.

@heda I added this to code:

Code: Select all

print('verticies ', circle1.Shape.Vertexes)
And got this:
verticies []
Sorry misspelled
User avatar
onekk
Veteran
Posts: 6206
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Help wih arc

Post by onekk »

jfc4120 wrote: Sun Jul 24, 2022 5:13 pm @onekk thanks for answers. But also using this code:

Code: Select all

zaxis = App.Vector(0, 0, 1)
p1 = App.Vector(0, TCLRD + WD, 0)
place1 = App.Placement(p1, App.Rotation(zaxis, 0))
circle1 = Draft.make_circle(TCLRD, placement=place1, face=None, startangle=270 - ELDG, endangle=270, support=None)
And that is using the example in the documentation.

Is there a way to get the begin point and end point of that arc? Or do I have to use part library or what.
I rarely use Draft as Part is more low level, and surely respect the Topology Chain.

with great approximations shape - faces - wires - edges - vertexes

Draft is not bad, but it returns DocumentObjects, so you have some side effects, you have all the intermediate objects that for complex objects will enlarge the file size.

So I prefer to use Part and explicitly use Part.show to explicity visualize things.

I rarely use Draft as there is some overhead built on Shapes (In fact it was made to ease some geometric works.) and have some more high level constructs, but I prefer the low level ways as it expose more cleanly OCCT primitives.

As example in Part you have Part.Line (that is the line of geometry so an infinite line passing from two point) and the more used Part.LineSegment that is the segment that join two points.

Plus with Part you could use Curves and limit them using toShape(min, max) that is more near to the way OCCT work.

Draft is taylored to resemble more a 2D CAD program that produce everytime something to display.

Part is more near to the concept of "building block" and you could see in the second example the use when building patametric solids creating wires faces solud but also manipulate them using some things like the offset2d thing that is very powerful once you know his limitations.

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/
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Help wih arc

Post by jfc4120 »

@onekk I am going to study over your examples and try to get a good understanding.

Edit:

I still wish draft mode had line tangent to Circle snap.

Is there a way to achieve that in part.
User avatar
onekk
Veteran
Posts: 6206
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Help wih arc

Post by onekk »

there are some ways, but tangent calculations give two solutions.

I've had solutions but now I'm on mobile so no link available for now.

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/
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: Help wih arc

Post by heda »

from the first example code in your first basiccad post...

Code: Select all

    arco = Draft.make_circle(tr + cw, startangle=0, endangle=ang)
    doc.recompute()
    # otherwise the objects are not properly populated
no worries though, fully aware of it takes a while to actually absorb everything that is passing by...
just hang in there and this initial phase will be over before you know it.


so, it looks like this in the console

Code: Select all

>>> zaxis = App.Vector(0, 0, 1)
>>> p1 = App.Vector(0, 0, 0)
>>> place1 = App.Placement(p1, App.Rotation(zaxis, 0))
>>> circle1 = Draft.make_circle(5, placement=place1, face=None, startangle=0, endangle=90, support=None)
>>> print('verticies ', circle1.Shape.Vertexes)
verticies  []
>>> App.ActiveDocument.recompute()
1
>>> print('verticies ', circle1.Shape.Vertexes)
verticies  [<Vertex object at 0x55cf61a200b0>, <Vertex object at 0x55cf6035a350>]
>>> v1, v2 = circle1.Shape.Vertexes
>>> print(v1, v1.X)
<Vertex object at 0x55cf62b88370> 5.0
>>> 
>>> v1.Point
Vector (5.0, 0.0, 0.0)
>>> list(v1.Point)
[5.0, 0.0, 0.0]
>>> 
edwilliams16
Veteran
Posts: 3180
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Help wih arc

Post by edwilliams16 »

If your workflow is to construct your 2D geometry using the Draft workbench, then pasting the following in line by line into the Python console will show you the tools you have available, and provide a skeleton tutorial. I would avoid using Placements, since you are only working in the Global XY-Plane. They are more suited to moving objects around in 3D space.

Code: Select all

#draw an arc
arc1 = Draft.make_circle(200, startangle=10, endangle=80)
v1, v2 = arc1.Shape.Vertexes # vertex objects
p1 = v1.Point
p2 = v2.Point #location vectors
lin = Draft.makeLine(p1, p2) #draw a line between the ends

#construct a tangent at p1 
edge = arc1.Shape.Edges[0] # arc has one edge
dir1 = edge.tangentAt(edge.FirstParameter)
lin1 = Draft.makeLine(p1, p1 - 50 * dir1) #draw a line along the tangent direction 
                                                             #(minus because tangent points along the curve direction)

#construct a line, normal to arc at p2
dir2 = edge.normalAt(edge.LastParameter) #undefined for a line - instead you'd use App.Vector(0,0,1).cross(dir)
p3 = p2 + 100 * dir2
lin2 = Draft.makeLine(p2, p3)

# draw a line at 30 degree CC from p3 
rot = App.Rotation(App.Vector(0,0,1), 30) #30 deg rotation around z axis
dir3 = rot * dir2 # applied to dir2 (overloaded rot.multVec(dir2) )
lin3 = Draft.makeLine(p3, p3 + 25 * dir3)

# find the midpoint of the arc?
pmid = edge.valueAt((edge.FirstParameter + edge.LastParameter)/2) 
#draw a point there
Draft.makePoint(pmid)

#draw a line from p3 to pmid - and find it's intersection with lin1
lin4 = Draft.makeLine(p3, pmid)
lincurve= lin.Shape.Edges[0].Curve #we go down to the geometry level to find the intersection
lin4curve = lin4.Shape.Edges[0].Curve
points = lincurve.intersect(lin4curve) #list of one intersection
pointloc = App.Vector(points[0].X, points[0].Y, points[0].Z)
Draft.makePoint(pointloc)



I've constructed lines, arcs, tangents, normals, intersections above. If you need other shapes, looking at the completions of Draft.make in the Python console will show you what's available. Also typing help(obj) on any object will show methods.
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Help wih arc

Post by jfc4120 »

@onekk I can do a tangent fairly easy either with trig or usually:

Code: Select all

Call T the tagent line 

You measure the point outside circle to center, example is: 23.20

Then 23.20 squared  -  Radius squared = T

Then draw a wire (T, 0, 0)  and  (0, RADIUS, 0)   Up or down depending on drawing.

Then simply move / rotate in position.
I am working on a macro that will draw two small lines at the two tangent points also using trig, then you can pick which is needed and delete stray lines.

But will still have to input length of outside point to circle center and radius.

And @edwilliams16 I am going to study and practice the sample code you posted, thanks to all who answered.
Attachments
t1.png
t1.png (11.76 KiB) Viewed 372 times
t2.png
t2.png (13.8 KiB) Viewed 372 times
t3.png
t3.png (14.98 KiB) Viewed 372 times
User avatar
onekk
Veteran
Posts: 6206
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Help wih arc

Post by onekk »

Probably this will help, I've used a modified version of @edwilliams16 methods from this post.

https://forum.freecadweb.org/viewtopic. ... 27#p563627

Probably there are better ways, but it works.
20220725-tangents.py
(4.03 KiB) Downloaded 11 times
PS in the code you will note some tricks that works on 0.20 as it use Part.show that returns the objects created, I don't remember if it works prior of 0.20.

Hope it helps.

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