Could anyone share a trick to avoid errors caused by python internal rounding?
import rhinoscriptsyntax as rs
import math
listX = []
for i in range(n):
listX.append(((p2.X - p1.X)/(n-1))*i)
print(listX)
r = p2.X - p1.X
print(r)
pts = []
for k in range(n):
pts.append(rs.AddPoint(round(listX[k],3),-round((math.sqrt(r**2 - (listX[k]-p1.X)**2)-p2.Y),3)))
It may be the sqrt call. I would suggest breaking line 39 into several lines of code. There is too much packed into that single line to determine where the real problem lies.
Still though even if I âunpackâ that line into
pts = []
for k in range(n):
tmpX=round(listX[k],3)
tmpY=-round((math.sqrt(r**2 - (listX[k]-p1.X)**2)-p2.Y),3)
tmpPt = rs.AddPoint(tmpX,tmpY)
pts.append(tmpPt)
You can use the decimal module in Python if you need to do precise decimal arithmetic. At some point you need to turn the answer into a float to use it with rhino.