Hey, I’ve been trying to figure out how to convert an angle(solved) from two lengths and convert that to
a Vector3 position in 3D space. So far, I have no idea how to go about this.
I’ve been trying to make a method relating to Inverse Kinematics. It takes two points, draws segments(via midpoint) and uses a defined midpoint to calculate Size.Z
for each segment.
For whatever reason, I can’t seem to figure out a way to convert an angle, that I solve for using Law of Cosines, to a valid vector3 position(where the midpoint should be). Typically, IK is not solved like this but, I figured that I could try it out. The way I set it up is that there’s two segments. Segment 1 spans from start(Shoulder) to the midpoint. Segment 2 spans from the midpoint to goal(end-effector). In theory, I should be able to move the midpoint to get the correct position of segment 2. However, oddly enough I have no idea to determine the midpoint’s vector3 position after the end-effector has moved.
Shown in the video below, I know the angle that both segments should be making, but I have no clue how to produce that programically.
Programically, it looks something like this:
-- Midpoint Formula
midpoint.Position = Vector3.new((start.Position.X+goal.Position.X)/2,(start.Position.Y+goal.Position.Y)/2,(start.Position.Z+goal.Position.Z)/2)
-- Distance Formula
distance1 = math.sqrt((midpoint.Position.X-start.Position.X)^2+(midpoint.Position.Y-start.Position.Y)^2+(midpoint.Position.Z-start.Position.Z)^2)/2
-- Segment Sizing
seg1.Size = Vector3.new(1.3,1.3,(distance1-1.3)/2)
seg2.Size = Vector3.new(1.3,1.3,(distance1-1.3)/2)
-- Code on this line is basic cframe to position segments to start -> midpoint & midpoint -> goal respectively
-- v1 = Segment 1, v2 = Segment 2
-- Shoulder = start, Goal = goal
local a = tonumber(math.sqrt(v1.Position.X^2+v1.Position.Y^2+v1.Position.Z^2))
local b = tonumber(math.sqrt(v2.Position.X^2+v2.Position.Y^2+v2.Position.Z^2))
local c = (shoulder.Position-goal.Position).magnitude
local A = math.acos((-a^2+b^2-c^2)/(2*b*c))
local C = math.acos((a^2+b^2-c^2)/(2*a*b))
Here’s what I have so far:
https://streamable.com/5j7dd
Just a small disclaimer, I’m aware that this is not the most conventional way to do this but, so far up until this point, it’s been working for me, could be totally wrong, but works. I’m not entirely sure if it qualifies as IK. Anywho, I appreciate those who choose to respond.