Find the perpendicular point (on other curve) to a point on a curve


I wanted to find a point on other curve which is perpendicular to the point of my interest

The below image shows 3 curves, which has points on it

for example, if i select a point (pt_a) on line2/curve2, i should get a perpendicular point (pt_b) which is perpendicular to pt_a lying on line1/curve1.
if there is no perpendicular point, then the point that is nearer to perpendicular should be chosen

Can you suggest me, if there is any function in python that can achieve my task, or can you suggest me procedure i can follow to achieve this task

Thanks in advance

find_perpendicular_pt_on_othercurve.stp (250.8 KB)

You perhaps want to look at rhinoscriptsyntax.CurveClosestPoint() -

or in RhinoCommon Rhino.Geometry.Curve.ClosestPoint()

(the line back from the closest point to the base curve is generally also perpendicular to the base curve except where the test object does not have a possible perpendicular, then it is the nearest point)

Hello - do you specifically want to do this in Python? In plain Rhino the command is ClosestPt, use the Near or OnCrv osnap to set your test point.


import rhinoscriptsyntax as rs
def perpendicular_distance_bw_curve_and_pt(curve, point):
    rs.Command("-_ClosestPt " + str(rs.SelectObject(curve)) + " _Enter "+ str(rs.SelectObject(point)))
    guid =rs.LastCreatedObjects()
    return guid


Can you help me in the code, i dont know how to handle ClosestPt in rs.command

Thanks in Advance

You’d better to use rs.CurveClosestPoint:

import rhinoscriptsyntax as rs
id = rs.GetObject("Select a curve")
if id:
    point = rs.GetPoint("Pick a test point")
    if point:
        param = rs.CurveClosestPoint(id, point)
        closestPt = rs.EvaluateCurve(id, param)

Thank you @Mahdiyar.

Actually i really need something that when i select a point, it should give me a point that is perpendicular to it

find_perpendicular_pt_on_othercurve.stp (249.7 KB)

Thanks in advance

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
crvA = rs.GetObject("Select a curve")
point =rs.GetPointOnCurve(crvA, "Pick a test point")
param = rs.CurveClosestPoint(crvA, point)
PtA = rs.EvaluateCurve(crvA, param)
tanVec = rs.CurveTangent(crvA, param)
norVec = rs.VectorCrossProduct(tanVec, rs.CurveNormal(crvA))
crvB = rs.GetObject("Select a curve")
result = rg.Intersect.Intersection.CurveLine(rs.coercecurve(crvB), rg.Line(PtA,norVec+PtA),0.1,0.1)
for pt in result:
    rs.AddPoint(pt.PointA) (520 Bytes)

1 Like