Create an Arc with 3 inputs (End points and radius only)

I need to plot an arc with endpoints and radius (3 inputs only), however this function does no exist within rhinoscriptsyntax or rhino.geometry but only as an actual built-in tool. I would sincerely appreciate if anybody has created this function of could assist me with this matter.

Regards,

HMR

import Rhino.Geometry as rg
import rhinoscriptsyntax as rs
pt1 = rs.GetPoint("Start of arc")
pt2 = rs.GetPoint("End of arc")
r = rs.GetReal("Radius of arc")
d = pt1.DistanceTo(pt2)
x = (r**2 - (d**2)/4)**0.5
midPt = (pt1+pt2)*0.5
normalVector = rs.CurveNormal(rs.AddLine(pt1,pt2))
vector = rs.VectorCrossProduct(pt2-pt1, normalVector)
vector.Unitize()
vector *= x
center = midPt - vector
pt3 = ((center-pt1)*2)+pt1
rs.AddArc3Pt(pt1,pt2,pt3)

Horacio.py (454 Bytes)

Hi Mahdiyar,

Thanks for the help. I had to modify the function as I am currently using it in a long script where I read data from a csv file. I noticed that the function is not actually plotting correctly. Please have a look at it if possible.

Thanks,

HMR

#Calls specific 2d points from a list and assign them as variables
def GenerateStockRails():

StartPoint = TR[0] #(x,y)
EndPoint = TR[1] #(x,y)
Radius = TR[2][0]  #radius value
#if both y coordinates are the same plot line
if StartPoint[1] == EndPoint[1]:
    TRC = rs.AddLine(StartPoint,EndPoint)
#plot curves
if StartPoint[1] != EndPoint[1]:
    TRC = ArcCreation(StartPoint, EndPoint, Radius)
    
StartPoint = BR[0] #(x,y)
EndPoint = BR[1] #(x,y)
Radius = BR[2][0] #radius value

if StartPoint[1] == EndPoint[1]:
    BRC = rs.AddLine(StartPoint,EndPoint)
if StartPoint[1] != EndPoint[1]:
    BRC = ArcCreation(StartPoint, EndPoint, Radius)
return (TRC, BRC)

def ArcCreation(pt1,pt2,r):
#pt1 = rs.GetPoint(“Start of arc”)
#pt2 = rs.GetPoint(“End of arc”)
#r = rs.GetReal(“Radius of arc”)
d = rs.VectorLength(rs.VectorCreate(pt1,pt2))
x = (r2 - (d2)/4)**0.5
midPt = rs.VectorScale(rs.VectorAdd(pt1,pt2),0.5)
normalVector = rs.CurveNormal(rs.AddLine(pt1,pt2))
vector = rs.VectorCrossProduct(rs.VectorSubtract(pt2,pt1), normalVector)
vector.Unitize()
vector *= x
center = rs.VectorSubtract(midPt,vector)
pt3 = rs.VectorAdd(rs.VectorScale(rs.VectorSubtract(center,pt1),2),pt1)
rs.AddArc3Pt(pt1,pt2,pt3)


123

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
def ArcSER(pt1,pt2,r):
    d = rs.VectorLength(rs.VectorCreate(pt1,pt2))
    x = (r**2 - (d**2)/4)**0.5
    midPt = rs.VectorScale(rs.VectorAdd(pt1,pt2),0.5)
    normalVector = rs.CurveNormal(rs.AddLine(pt1,pt2))
    vector = rs.VectorCrossProduct(rs.VectorSubtract(pt2,pt1), normalVector)
    vector.Unitize()
    vector *= x
    center = rs.VectorSubtract(midPt,vector)
    pt3 = rs.VectorAdd(rs.VectorScale(rs.VectorSubtract(center,pt1),2),pt1)
    rs.AddArc3Pt(pt1,pt2,pt3)

ArcSER([0,0,0],[0,10,0], 10)

Hi,

For all of those that may want to do something similar in the future. Here I attach what worked for me.

def CircleCenter(Pt1,Pt2,R):
if R<0:
ChordVector = rs.VectorCreate(Pt1,Pt2)
ChordLength = rs.VectorLength(ChordVector)
a = ChordLength0.5
x = (R2 - (ChordLength2)/4)**0.5
d = R - x
Ptm = list(rs.VectorScale(rs.VectorAdd(Pt1,Pt2),0.5))
Diff = rs.VectorSubtract(Pt1,Ptm)
Ptc = [Ptm[0]+(x
Diff[1])/a,Ptm[1]-(xDiff[0])/a]
if R>0:
ChordVector = rs.VectorCreate(Pt1,Pt2)
ChordLength = rs.VectorLength(ChordVector)
a = ChordLength
0.5
x = (R2 - (ChordLength2)/4)**0.5
d = R - x
Ptm = list(rs.VectorScale(rs.VectorAdd(Pt1,Pt2),0.5))
Diff = rs.VectorSubtract(Pt1,Ptm)
Ptc = [Ptm[0]-(xDiff[1])/a,Ptm[1]+(xDiff[0])/a]
return (Ptc)

def ArcCreation(Pt1,Pt2,R):
ChordVector = rs.VectorCreate(Pt1,Pt2)
ChordLength = rs.VectorLength(ChordVector)
D = R*2
if ChordLength <= D:
x = (R2 - (ChordLength2)/4)**0.5
d = R - x
HalfChordPoint = list(rs.VectorScale(rs.VectorAdd(Pt1,Pt2),0.5))
Center = CircleCenter(Pt1,Pt2,R)
NegCenter = rs.VectorScale(Center,-1)
Vector = rs.VectorCreate(HalfChordPoint,Center)
UnitVector = rs.VectorUnitize(Vector)
ScaledVector = rs.VectorScale(UnitVector,R)
Pt3 = rs.VectorCreate(ScaledVector,NegCenter)
rs.AddArc3Pt(Pt1,Pt2,Pt3)

cORRECTED SCRIPT:

def CircleCenter(Pt1,Pt2,R):
if R<0:
ChordVector = rs.VectorCreate(Pt1,Pt2)
ChordLength = rs.VectorLength(ChordVector)
a = ChordLength0.5
x = (R2 - (ChordLength2)/4)**0.5
d = R - x
Ptm = list(rs.VectorScale(rs.VectorAdd(Pt1,Pt2),0.5))
Diff = rs.VectorSubtract(Pt1,Ptm)
Center = [Ptm[0]+(x
Diff[1])/a,Ptm[1]-(xDiff[0])/a]
elif R>0:
ChordVector = rs.VectorCreate(Pt1,Pt2)
ChordLength = rs.VectorLength(ChordVector)
a = ChordLength
0.5
x = (R2 - (ChordLength2)/4)**0.5
d = R - x
Ptm = list(rs.VectorScale(rs.VectorAdd(Pt1,Pt2),0.5))
Diff = rs.VectorSubtract(Pt1,Ptm)
Center = [Ptm[0]-(xDiff[1])/a,Ptm[1]+(xDiff[0])/a]
return (Center)

def ArcCreation(Pt1,Pt2,R):
ChordVector = rs.VectorCreate(Pt1,Pt2)
ChordLength = rs.VectorLength(ChordVector)
D = R*2
if ChordLength <= abs(D):
x = (R2 - (ChordLength2)/4)**0.5
d = abs® - x
Ptm = list(rs.VectorScale(rs.VectorAdd(Pt1,Pt2),0.5))
Center = CircleCenter(Pt1,Pt2,R)
NegCenter = rs.VectorScale(Center,-1)
Vector = rs.VectorCreate(Ptm,Center)
UnitVector = rs.VectorUnitize(Vector)
ScaledVector = rs.VectorScale(UnitVector,abs®)
Pt3 = rs.VectorCreate(ScaledVector,NegCenter)
rs.AddArc3Pt(Pt1,Pt2,Pt3)
rs.ZoomExtents(Pt3, all=True)