Page 1 of 1

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

Posted: Sat Jun 25, 2022 2:57 pm
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?

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

Posted: Sat Jun 25, 2022 6:52 pm
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.

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

Posted: Sun Jun 26, 2022 8:06 am
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.

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

Posted: Sun Jun 26, 2022 8:15 am
by Chris_G

Code: Select all

distance, points, info = edge.distToShape(vertex)
should return all solutions, i think.

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

Posted: Sun Jun 26, 2022 8:54 am
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))]

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

Posted: Sun Jun 26, 2022 10:54 am
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.

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

Posted: Sun Jun 26, 2022 5:19 pm
by Chris_G

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

Posted: Sun Jun 26, 2022 6:31 pm
by Roy_043
That's great. Thank you very much!