New Circle Tangent To A Line or Curve

Using Python Script.

What’s the easiest way to create a new circle tangent to an existing line or curve and also be able to select the side of the line / curve that the circle goes on?

1 Like

Hi Mike - here is a basic and clunky way - uses rhinoscriptsyntax for the most part - it is not too hard to make it cleaner and more interactive etc with RhinoCommon, depending on what you want to do.

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc



def test():
    
    id = rs.GetObject(filter = 4, preselect=True)
    if not id:return

    
    p1 = rs.GetPointOnCurve(id)
    if not p1: return
    
    t1 = rs.CurveClosestPoint(id, p1)
    
    vecDir = rs.CurveTangent(id, t1)
    frame = rs.CurveFrame(id,t1)
    
    #    p2 = rs.GetPoint('Click on the side to create the circle.')
    
    rad = 1 
    if 'CIRC_RAD' in sc.sticky:
        rad = sc.sticky['CIRC_RAD']
        
    rad = rs.GetReal('radius?', rad)
    if not rad: return
    
    temp = Rhino.Geometry.Plane(frame)
    temp.Origin = p1 + (frame.YAxis*rad)

    tryCircle = rs.AddCircle(temp,rad)
    
    flip = rs.GetBoolean('Flip?', ('Flip', 'No', 'Yes'), [False])[0]
    
    
    if flip:
        rs.DeleteObject(tryCircle)
        vecDir = frame.YAxis
        vecDir.Reverse()
        temp.Origin = p1 + (vecDir*rad)
        rs.AddCircle(temp,rad)


test()

-Pascal

Ok great…thanks. I’ll try it out.