 Author Topic: Trying to find an angle  (Read 1697 times) idkm23

• byte
• • Posts: 34 Trying to find an angle
« on: March 11, 2016, 12:06:35 am »
Hello, I have a somewhat simple question involving some math being applied to the model. I am applying a rotation matrix on a shoulder joint on a model (see below) and I want to find an angle out of it (see the yellow). My first attempt was to convert the rotation matrix to euler angles and then check if any of the coordinates had the result I want. However, none of the rpy corresponded to this. Is there a way to extract this information? There must be, right? Any help is greatly appreciated, let me know if I was unclear!  EgonOlsen

•     • • Posts: 11985 Re: Trying to find an angle
« Reply #1 on: March 11, 2016, 09:27:58 am »
I'm not sure if this idea is applicable, but...

...if you have the rotation matrix, you could extract the rotated axes from it (Matrix.get?Axis()). You could then use this: http://www.jpct.net/doc/com/threed/jpct/SimpleVector.html#calcAngle(com.threed.jpct.SimpleVector) to calculate the angle between the fitting axis (z?) and, in case of z, (0,0,-1). That will return an unsigned angle that describes the shortest angle between these two vectors. Maybe that's a start. If you need it signed, you have to apply some additional logic like comparing directions or such. idkm23

• byte
• • Posts: 34 Re: Trying to find an angle
« Reply #2 on: March 11, 2016, 07:44:38 pm »
It doesn't appear to correspond to any of the axes. I tried for X, Y, and Z. I think that method won't work in this case because some of the axes are dependant on eachother. What I mean is like, when I rotate with X, then the Z axis moves and so the meaning is completely different.

I will show another example since I wasn't clear the first time, except this time with the angle being applied to the elbow.

This image's angle would be 0 This angle would be 180 Any guidance is appreciated  idkm23

• byte
• • Posts: 34 Re: Trying to find an angle
« Reply #3 on: March 11, 2016, 07:54:01 pm »
One thing I forgot to mention, if I tried it for the y-axis it corresponded to the angle properly, but if the arm is rotated so it does not come to a 90 degree with the bicep or if its twisted then it no longer corresponds to the correct values. In the images above it could get the values correctly because the hand isnt rotating much and it comes to a 90 degree with the bicep.

The reason why I want to get this angle is so I can unallow movements which fall under a certain range for simple collision detection so the forearm cant phase into the model's chest. I am open to other ideas for this. As an alternative, I was thinking possibly grabbing a vertex from the tip of the models hand and seeing if it is in a bad coordinate zone. What do you think?
« Last Edit: March 11, 2016, 08:29:03 pm by idkm23 » EgonOlsen

•     • • Posts: 11985 Re: Trying to find an angle
« Reply #4 on: March 14, 2016, 01:07:56 pm »
I think that my method should work, but you would have to take the complete transformations into account, i.e. using the matrix on a joint isn't enough. You have to use the complete translation matrix. I'm not sure, if Bones provides this.

About the vertex solution: That's most likely what I would have done (which doesn't mean that it's the best solution though...). idkm23

• byte
• • Posts: 34 Re: Trying to find an angle
« Reply #5 on: March 14, 2016, 03:09:47 pm »
How exactly might one find that point? I thought the vertices were stored in the Mesh class, but I cant seem to actually access them. By a complete translation matrix, do you mean like the combinations of all matrices of the previous joints in the hierarchy? I'll look into your idea again, thanks for the help.

Edit: I was doing something wrong in my code. I was actually finding the Y-axis of the transformation AFTER multiplying the shoulder (I should NOT have done this). After undoing this mistake I have gotten more reasonable results, although I am still more interested in accessing the points of the mesh.
« Last Edit: March 14, 2016, 04:53:16 pm by idkm23 » EgonOlsen

•     •  