How can I find the closest point on two lines?
I realize I can find the closest point on a line from a Point3d.
But I’m not sure how to always find the closest point between the two lines. Could I use Vector3d.angle_between somehow?
How can I find the closest point on two lines?
I realize I can find the closest point on a line from a Point3d.
But I’m not sure how to always find the closest point between the two lines. Could I use Vector3d.angle_between somehow?
What I’m really trying to do is find the closest point on a line from my input point.
I want to constraint the input to the closest position on the ridge.
You can see it’s not working quite right.
Here is my code so far.
if @is_cupola
view.pick_helper.do_pick(x, y, 50)
peak = (1..view.pick_helper.count).map { |i| [view.pick_helper.leaf_at(i - 1), view.pick_helper.transformation_at(i - 1)] }
.select { |e| e[0].get_attribute('bc', 'type') == 'peak' }[0]
if peak
ray = view.pickray(x, y)
ray[1].length = (ray[0] - peak[0].bounds.center.transform(peak[1])).length
ray_point = ray[0] + ray[1]
end
if peak.to_a[0] != @peak
@model.selection.clear
@model.selection.add(peak[0]) if peak
end
@peak = peak.to_a[0]
@peak_transformation = peak.to_a[1]
projected_point = ray_point.project_to_line(@peak.start.position.transform(@peak_transformation), @peak.end.position.transform(@peak_transformation)) if @peak && point
point = projected_point if projected_point
end
Just an idea: Instead of pickray, probably you can combine with the view.inputpoint
…
Something like :
.
if peak
.
.
ip = view.inputpoint(x, y)
projected_point = ip.position.project_to_line((@peak.start.posi...
.
.
end
I searched for a long time… I should just have went to bed like my wife suggested.
Really ?
Result …
Thanks I never used that before.
… betcha will from now on.