RobinB


«
Posted
20130824 19:25:07 » 

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). 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 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)); float downarm = (float)Math.acos((c*c + a*a  b*b)/(2*a*c));
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?




Several KiloBytes


«
Reply #1  Posted
20130824 20:13:05 » 

Here are formulas you can use to find the angles of a triangle given three sides: A^2 + B^2  A*B*cos(angle ab) = C^2 sin(angle a) / A = sin(angle b) / B = sin(angle c) / C
I can't infer what you are trying to do, but I noticed you are not using complex numbers or matrices. Is there a reason why you use angles?




RobinB


«
Reply #2  Posted
20130824 20:56:50 » 

My biggest problem at the moment is calculating line BD (cant figure out its length). Im aware of the cosinus rule, but i dont have all sides of th second rectanglr (ABD), so i cant use it Im trying to find the angles to rotate the joints of the bones in the characters arm (bone structure). 1 2
 leftuparm.RotateX(up); leftdownarm.RotateX(down); 
Reason i dont use complex numbers and matrices is because i cant get that far with math. Using simple trigoniomerty i came this far, but any changes are appriciated.




Games published by our own members! Check 'em out!


DrZoidberg


«
Reply #3  Posted
20130824 21:02:03 » 

So you have a coordinate x,y,z and you want the arm to point towards that position? In which form do you need the angles? What library do you use? Can't you give it the direction in another way?




Agro


«
Reply #4  Posted
20130824 21:02:47 » 

learn some inverse kinematics 8D




RobinB


«
Reply #5  Posted
20130824 21:06:27 » 

The model consists of joints (the red dots). Thats indeed what im trying to do, thank you *Do you have any self explaining article?




RobinB


«
Reply #6  Posted
20130824 21:25:17 » 

I cant find any implementation of (reverse) kinematics, mostly it says i have to solve it using simple trigoniomerty. So could anyone help me with calculating line BD?




Several KiloBytes


«
Reply #7  Posted
20130824 22:25:24 » 

The only "simple" trig you need to know is the names of relationships on a right triangle (sine, cosine, tangent, cotangent, secant, cosecant, and their inverses) (just the names), the two equations I wrote (which are for nonright triangles), and how to convert Cartesian to polar coordinates. There is no simple or complicated trig. That is the entirety of it.
You need to know an angle of abd. C is the side opposite angle c. Let c be that angle and C be the side opposite it (72, 100, or bd). A and B are the other two sides. You have one unknown, so that is the only equation you need to solve.
If you know only two sides and none of the angles, the third side of the triangle could be any length greater than 72 + 100, so it is impossible to solve for the unknown side length.




philfrei


«
Reply #8  Posted
20130825 05:01:28 » 

@RobinB  I don't think you have enough info in your diagram to determine length BD. It seems to me BD could be almost any length, based on different possible angles BAD. Knowing the internal angles of ABC doesn't really help, as according to your figure, the angles in ADB are independent of ABC. I was looking at the wikipedia post. http://en.wikipedia.org/wiki/Solution_of_trianglesAnd found a way to get the internal angles of ABC there. ("Three Sides Given") But that was when I realized, ADB is independent and that this doesn't help.

"It's after the end of the world! Don't you know that yet?"



RobinB


«
Reply #9  Posted
20130825 07:56:41 » 

Thank you both, im really bad at this.
Line AB is the upper arm, do you have any idea how i can get the needed rotation?




Games published by our own members! Check 'em out!


Several KiloBytes


«
Reply #10  Posted
20130825 17:00:13 » 

All I see are triangles. I do not know what direction/distance each line is supposed to go. Speaking of which, vectors are a means of encoding direction and distance into the same number for any number of dimensions and there are even fewer operations to learn than in trig. (Dot product, cross product, addition, scalar multiplication, normalization, and matrix multiplication.)




philfrei


«
Reply #11  Posted
20130825 17:11:33 » 

Using the wikipedia link formula for "angle of cosines" solution, when given 3 side lengths: http://en.wikipedia.org/wiki/Solution_of_triangles1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 double ab = 72; double bc = 53; double ca = 64; double cab = Math.acos( ( (ab * ab) + (ca * ca)  (bc * bc)) / (2 * ab * ca) ); double abc = Math.acos( ( (ab * ab) + (bc * bc)  (ca * ca)) / (2 * ab * bc) ); double bca = Math.PI  (cab + abc); System.out.println("cab:" + cab * 180 / Math.PI); System.out.println("abc:" + abc * 180 / Math.PI); System.out.println("bca:" + bca * 180 / Math.PI); 
Runs to give: 1 2 3
 cab:45.40037140150904 abc:59.29531617541667 bca:75.30431242307428 
I should mention, I just hacked this out from the wikipedia solution, and have no idea if it is the most practical or efficient for your situation.

"It's after the end of the world! Don't you know that yet?"



RobinB


«
Reply #12  Posted
20130825 19:33:47 » 

Using the wikipedia link formula for "angle of cosines" solution, when given 3 side lengths: http://en.wikipedia.org/wiki/Solution_of_triangles1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 double ab = 72; double bc = 53; double ca = 64; double cab = Math.acos( ( (ab * ab) + (ca * ca)  (bc * bc)) / (2 * ab * ca) ); double abc = Math.acos( ( (ab * ab) + (bc * bc)  (ca * ca)) / (2 * ab * bc) ); double bca = Math.PI  (cab + abc); System.out.println("cab:" + cab * 180 / Math.PI); System.out.println("abc:" + abc * 180 / Math.PI); System.out.println("bca:" + bca * 180 / Math.PI); 
Runs to give: 1 2 3
 cab:45.40037140150904 abc:59.29531617541667 bca:75.30431242307428 
I should mention, I just hacked this out from the wikipedia solution, and have no idea if it is the most practical or efficient for your situation. Thank you, but this is the same code as i have above. The problem is that corner a does not rotate the upper arm like it should. The only usable angle in this rectangle is B, because this represents the rotation of the lower arm to the upper arm. I need to find the angle beteen the arm in default position (line AD) and the arm in current position (line AB), so i can rotate it accordingly.




philfrei


«
Reply #13  Posted
20130825 20:20:27 » 

oops [re: same solution] From you diagram, is AD always vertical? That might help. Do you have the [x, y] of two of the three points A, B, C? Otherwise, it seems the top triangle could be rotated to almost any angle, so there would be no way to know the angle at which AB veers off of the vertical. Also, angle B (internal to ABC) has no bearing on angle A or B (internal to (ABD). If both angle A (internal to ABD) and line BD are unknown, there are an infinite number of solutions, as changing one will change the other. More info needs to be provided.

"It's after the end of the world! Don't you know that yet?"



RobinB


«
Reply #14  Posted
20130825 21:12:18 » 

Apologies for my bad explanations. The line AD should indeed be vertical (so i have a refrence point to rotate from). The following image shows what im trying: Point c is known (position of the hand). Point a is also known (torso base position) Line AB = 72 Line BC = 53 I want to rotate line AB and CD so the hand will be placed at the position of c. I figured i should make 2 rectangles and calculate the needed angles, but this seems to be kinda hard. How can i find out at what angle i should rotate these lines so the hand will be placed at point c?




philfrei


«
Reply #15  Posted
20130825 21:49:30 » 

Given location A and C, you can easily get length AC.
Given lengths AC, AB, BC, you can get the internal angles A, B and C using the earlier formula.
Given locations A, C you can also get the angle or slope of AC off of the vertical, and then subtract the internal angle A from the previous step to get the angle (slope) of the line from A to B.
Yes?

"It's after the end of the world! Don't you know that yet?"



Several KiloBytes


«
Reply #16  Posted
20130825 21:59:27 » 

You know the length of three sides. That is enough to find all angles of abc using the law of sines. The position b can be found if you know a and c if you simply find the direction of ac, add a, and extend 72 units in that direction.




RobinB


«
Reply #17  Posted
20130826 03:50:15 » 

The problem is that angle a and c are useless for this problem. i need to find out how i should rotate a, to point line AB it to b. Thats why i made an external rectangle abd with a refrence point of 0 degrees.
With no refrence point i am not able to rotate the arm properly. Think what happens when i rotate the upper arm the same as angle a, it will not be in the position AB, what im really trying to.




philfrei


«
Reply #18  Posted
20130826 04:00:32 » 

I guess I don't understand the problem then. The rotation needed for AB, you are describing the angle that is formed by DA and AB. Yes? One way to get that angle is to subtract the inner angle A (AB to AC) from the angle formed by DA and AC. This IS possible because you can get the three lengths and then the inner angle A. AND you have the angle DA to AC because you know the location of A and C. ??

"It's after the end of the world! Don't you know that yet?"



RobinB


«
Reply #19  Posted
20130826 08:00:31 » 

The rotation needed for AB, you are describing the angle that is formed by DA and AB. Yes?
Correct AND you have the angle DA to AC because you know the location of A and C.
Thanks did not think of that, so i only need to figure out line CD then. Im going to try this stuff, thanks so much




RobinB


«
Reply #20  Posted
20130826 09:45:17 » 

OMG it worked, finally my days of frustration are over I only needed to use rectangle ACD to calculate the position of the upper arm :O Here and there some tweaking, and now its perfect. Thank you so much for bearing with me, im so happy :D




