How to get all perpendicular projections of a point on a curve?

Need help, or want to share a macro? Post here!
Post Reply
User avatar
Roy_043
Veteran
Posts: 5249
Joined: Thu Dec 27, 2018 12:28 pm

How to get all perpendicular projections of a point on a curve?

Post by Roy_043 »

For a face you can use this code to get all perpendicular projections of a point:

Code: Select all

doc = App.ActiveDocument
cone = doc.addObject("Part::Cone","Cone")
doc.recompute()
face = cone.Shape.Faces[0]
point = App.Vector(3,3,0)
face.Surface.projectPoint(point, "Parameters")
I am looking for a similar solution for curves.

This code only gives a single point:

Code: Select all

doc = App.ActiveDocument
circle = doc.addObject("Part::Circle","Circle")
doc.recompute()
edge = circle.Shape.Edges[0]
point = App.Vector(3,3,0)
edge.Curve.parameter(point)
Is there an existing solution for this?
edwilliams16
Veteran
Posts: 1358
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: How to get all perpendicular projections of a point on a curve?

Post by edwilliams16 »

Extruding the curve along the normal direction into a shell, using face.Surface.projectPoint(point, "Parameters") on the resulting face and picking off the u-parameters of the results worked for me.

Edit. Of course, I’m assuming that the curve and the point lie in a plane, as in your example.
User avatar
Roy_043
Veteran
Posts: 5249
Joined: Thu Dec 27, 2018 12:28 pm

Re: How to get all perpendicular projections of a point on a curve?

Post by Roy_043 »

Thanks for your suggestion, it's a clever idea. I am trying to improve Draft_Snap_Perpendicular. So there is no guarantee that the point and the curve are co-planar. Creating a shell may also prove to be too time-consuming in that context.
User avatar
Chris_G
Veteran
Posts: 2131
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: How to get all perpendicular projections of a point on a curve?

Post by Chris_G »

Code: Select all

distance, points, info = edge.distToShape(vertex)
should return all solutions, i think.
User avatar
Roy_043
Veteran
Posts: 5249
Joined: Thu Dec 27, 2018 12:28 pm

Re: How to get all perpendicular projections of a point on a curve?

Post by Roy_043 »

Thanks, but this also finds only a single point on the curve. It also finds a point on the shape, but since we are dealing with a vertex that point is already known.

Code: Select all

doc = App.ActiveDocument
circle = doc.addObject("Part::Circle","Circle")
doc.recompute()
edge = circle.Shape.Edges[0]
point = App.Vector(3,3,0)
distance, points, info = edge.distToShape(Part.Vertex(point))
print(points) # [(Vector (1.4142135623730951, 1.4142135623730951, 0.0), Vector (3.0, 3.0, 0.0))]
User avatar
Chris_G
Veteran
Posts: 2131
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: How to get all perpendicular projections of a point on a curve?

Post by Chris_G »

The surface method "projectPoint" could easily be ported to curves with the corresponding OCC method ProjectPointOnCurve
Maybe I can find time to do this in the coming days, unless someone else wants to do it.
User avatar
Chris_G
Veteran
Posts: 2131
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: How to get all perpendicular projections of a point on a curve?

Post by Chris_G »

User avatar
Roy_043
Veteran
Posts: 5249
Joined: Thu Dec 27, 2018 12:28 pm

Re: How to get all perpendicular projections of a point on a curve?

Post by Roy_043 »

That's great. Thank you very much!
Post Reply