I'm trying to plot some points along a 3D line segment and could really use some help. In 2D, I've found success getting the angle of the line, the sine & cosine of the angle, and then adding the cosine & sine to the starting point of the line's x & y respectively.
In 3D I think I'm getting the angle correctly and thus x & y using cosine and sine, but I'm not sure what to do for z. Can anyone please advise on how this is derived? Thank you!
def GetAngle(line):
fCrossX = line.p1.y * line.p2.z - line.p1.z * line.p2.y
fCrossY = line.p1.z * line.p2.x - line.p1.x * line.p2.z
fCrossZ = line.p1.x * line.p2.y - line.p1.y * line.p2.x
fCross = math.sqrt(fCrossX * fCrossX +
fCrossY * fCrossY + fCrossZ * fCrossZ)
fDot = line.p1.x * line.p2.x + line.p1.y * line.p2.y + line.p1.z + line.p2.z
return math.atan2(fCross, fDot)
v1 = Vector(100,0,0)
v2 = Vector(500,0,0)
line = Line(v1,v2)
angle = GetAngle(line)
sin = math.sin(angle)
cos = math.cos(angle)
points = list()
for i in range(int(line.length)):
x = line.p1.x+(cos*i)
y = line.p1.y+(sin*i)
# what do I do for z???
pt = Vector(x,y)
points.append(pt)