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

python
(Sumukha) #1

Hi,
Greetings!

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

Explanation:
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)

0 Likes

#2

You perhaps want to look at rhinoscriptsyntax.CurveClosestPoint() -
https://developer.rhino3d.com/api/RhinoScriptSyntax/#collapse-CurveClosestPoint

or in RhinoCommon Rhino.Geometry.Curve.ClosestPoint()
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Curve_ClosestPoint.htm

(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)

0 Likes

(Pascal Golay) #3

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.

-Pascal

0 Likes

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

Hi,

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

Thanks in Advance

0 Likes

#5

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)
        rs.AddPoint(closestPt)
0 Likes

(Sumukha) #6

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

0 Likes

#7

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)

sumuk.py (520 Bytes)

0 Likes