I want to script drawing the blue teardrop in the image below. Before going down my usual brute force and ignorance method of solving this I wonder if anyone’s got any bright ideas. What I want to do is pick the 2 red dots and be able to generate a tangential lead-in for a CNC toolpath.

I guess I can use CurveTangent to get to the centre of the arc then construct the rest from there.

Thanks Mark

emilio
August 6, 2016, 2:56pm
2
Hi Mark

here is a quick demo script

```
import rhinoscriptsyntax as rs
import Rhino
import math
def main():
ra = rs.GetReal( 'Radius ?' )
cu = rs.GetObject( 'Curve ?' )
p1 = rs.GetPoint( 'Point on curve ?' )
p2 = rs.GetPoint( 'Other point ?' )
uu = rs.CurveClosestPoint( cu, p1 )
p1 = rs.EvaluateCurve( cu, uu )
# 'vertical' axis: plane-with-curve normal or Z axis
kk = rs.CurveNormal( cu )
if not kk:
kk = [ 0, 0, 1 ]
ii = rs.CurveTangent( cu, uu )
# curve normal
jj = rs.VectorCrossProduct( ii, kk )
jj = rs.VectorUnitize( jj )
# possible center points
c1 = rs.VectorAdd( p1, rs.VectorScale( jj, ra ) )
c2 = rs.VectorSubtract( p1, rs.VectorScale( jj, ra ) )
# pick the center point on the right side
if rs.Distance( p2, c2 ) < rs.Distance( p2, c1 ):
c1 = c2
di = rs.Distance( p1, p2 )
degs = math.degrees( math.asin( ra / di ) )
vec = rs.VectorUnitize( rs.VectorCreate( c1, p2 ) )
vec1 = rs.VectorRotate( vec, -90 - degs, kk )
# joint point between line and arc ( 1 )
t1 = rs.VectorAdd( c1, rs.VectorScale( vec1, ra ) )
vec2 = rs.VectorRotate( vec, 90 + degs, kk )
# joint point between line and arc ( 2 )
t2 = rs.VectorAdd( c1, rs.VectorScale( vec2, ra ) )
# aux point do draw the arc
au = rs.VectorAdd( c1, rs.VectorScale( vec, ra ) )
rs.AddLine( p2, t1 )
rs.AddLine( p2, t2 )
rs.AddLine( p2, c1 )
rs.AddLine( p1, c1 )
rs.AddArc3Pt( t1, t2, au )
rs.AddTextDot( 'C1 X%.3fY%.3fZ%.3f' % ( c1.X, c1.Y, c1.Z ), c1 )
rs.AddTextDot( 'T1 X%.3fY%.3fZ%.3f' % ( t1.X, t1.Y, t1.Z ), t1 )
rs.AddTextDot( 'T2 X%.3fY%.3fZ%.3f' % ( t2.X, t2.Y, t2.Z ), t2 )
main()
```

HTH

Regards

1 Like

Hi emilio

Thanks you for the example script, works great. I’ll need to stare at it for a while so I can understand it well enough to put it to use in my project.

Thanks Mark

emilio
August 6, 2016, 4:25pm
4
Yes, it’s a quick 'n dirty script …
If something looks confusing, just ask.