Im trying to calculate the arms of the character to an certain position.
However im already stuck with the 2d calculation.
I need:
<A in ABD
<B in both triangles (added).
I have come up wih this code so far, but my math knowledge is really limited (all examples explain other aspects, mostly rectangles with 90 degree corners).
public void setLeftArm(float x, float y, float z){
float xdist = x - leftuparm.getParentJoint().getPos().x;
float ydist = y - leftuparm.getParentJoint().getPos().y;
float zdist = z - leftuparm.getParentJoint().getPos().z;
float a = leftdownarm.getHeight();
float b = (float)Math.sqrt(zdist * zdist + ydist * ydist);
float c = leftuparm.getHeight();
float d = 100;
float e = ?;
float uparm = (float)Math.acos((d*d + c*c - e*e)/(2*d*c)); //(b2 + c2 - a2)/2bc
float downarm = (float)Math.acos((c*c + a*a - b*b)/(2*a*c)); //(c2 + a2 - b2)/2ca
//Still need to add second corner from (ABD)
System.out.println("------------------------------");
System.out.println("Dist: " + xdist + " x " + ydist + " x " + zdist);
System.out.println("Rect 1: " + a + " x " + b + " x " + c);
System.out.println("Rect 2: " + c + " x " + d + " x " + e);
System.out.println("Angles: " + FastMath.RadtoDeg(up) + " x " + FastMath.RadtoDeg(down));
System.out.println("------------------------------");
}
In the future i also need to rotate taking the Z in account, i really have no clue how this is going to work.
Can anyone explain how i can get the needed rotations in 2D or even 3D space?