Hello,
I have a question that involves trigonometry if anyone out there can help in that area. I am using length units to place points along an arc and I want to make one point's distance relative to the other.
In this image, I am plotting a point (1) on an arc based on the arc length which I'm determining with this arccosine equation followed by the parametric equation for a circle.
angle = math.acos(1 - math.pow(d / radius, 2) / 2) #d is distance
newX = cx + radius * math.cos(angle) #cx is the arc's center x
newY = cy + radius * math.sin(angle) #cx is the arc's center y
I'm then creating a second point (2) based on the position of 1. I'm adding point 2's distance to the distance of Point 1.
When I run c4d.Vector.GetDistance(point1,point2)
, I would expect the distance to be the same as Point 2's distance, but it is not. Can anyone help me control Point 2's distance from Point 1 so that it's the same distance? I've attached my scene file and Python tag code if it's helpful. As always, thank you!
import c4d,math
def clamp(n, minn, maxn):
return max(min(maxn, n), minn)
def PosByDistance(cx, cy, d, radius):
a = 1 - math.pow(d / radius, 2) / 2
a = clamp(a, -1, 1)
angle = math.acos(a)
newX = cx + radius * math.cos(angle)
newY = cy + radius * math.sin(angle)
return c4d.Vector(newX, newY, 0)
def draw(bd):
node = op.GetObject()
bd.SetMatrix_Matrix(op=node, mg=node.GetMg(), zoffset=4)
bd.SetPointSize(10)
bd.SetPen(c4d.Vector(0.5, 0.5, 0.5))
off = node.GetMg().off
radius = node[c4d.PRIM_ARC_RADIUS]
dist = op[c4d.ID_USERDATA,2]
point1 = PosByDistance(off.x,off.y,dist,radius)
bd.DrawHandle(point1, type=c4d.DRAWHANDLE_CUSTOM, flags=0)
p2offset = op[c4d.ID_USERDATA,4]
point2 = PosByDistance(off.x,off.y,dist+p2offset,radius)
bd.SetPen(c4d.Vector(0, 1, 0))
bd.DrawHandle(point2, type=c4d.DRAWHANDLE_CUSTOM, flags=0)
op[c4d.ID_USERDATA,3] = str(round(c4d.Vector.GetDistance(point1,point2),2))
def main():
pass