2

I have two directions and i am trying to calculate the angle on a specific axis. The object from which the directions are derived is not a static object so i'm struggling to get my head round the maths to work out what i need to do.

FYI, I have the start and end points that i have used to calculate the directions if they are needed.

Here's a diagram to show what i am looking for:

The above image is from a top-down view in unity and it shows the angle i want.

The problem can be seen from the above image, which is that the directions are not on the same height so i can't use the vector3.angle function as it won't give me the correct angle value.

In essence i want to know how much would i have to rotate the red line to the left (top view) so that it would line up with the blue (top-view).

The reason i need this is as i am trying to find a way of getting the side-to-side angles of fingers from my leap motion sensor.

This a generic version of my other question: Leap Motion - Angle of proximal bone to metacarpal (side to side movement)

It will provide more specific information as to the problem if you need it and it has more specific screenshots.

**UPDATE: After re-reading my question i can see it wasn't particularly clear so here i will hopefully make it clearer. I am trying to calculate the angle of a finger from the leap motion tracking data. Specifically the angle of the finger relative to the metacarpal bone (bone is back of hand). An easy way to demonstrate what i mean would be for you to move your index finger side-to-side (i.e. towards your thumb and then far away from your thumb).

I have put two diagrams below to hopefully illustrate this. enter image description here

The blue line follows the metacarpal bone which your finger would line up with in a resting position. What i want to calculate is the angle between the blue and red lines (marked with a green line). I am unable to use Vector3.Angle as this value also takes into account the bending of the finger. I need someway of 'flattening' the finger direction out, thus essentially ignoring the bending and just looking at the side to side angle. The second diagram will hopefully show what i mean.

enter image description here

In this diagram: The blue line represents the actual direction of the finger (taken from the proximal bone - knuckle to first joint) The green line represents the metacarpal bone direction (the direction to compare to) The red line represents what i would like to 'convert' the blue line to, whilst keeping it's side to side angle (as seen in the first hand diagram).

It is also worth mentioning that i can't just always look at the x and z axis as this hand will be moving at rotating.

I hope this helps clear things up and truly appreciate the help received thus far.

user7856951
  • 503
  • 1
  • 4
  • 15
  • How about creating temporary 2d vectors for each of the lines so that they are on the same plane, and then use vector3.angle? – ryeMoss Feb 27 '18 at 16:09
  • How would i determine which axis to use given that the object is rotating and moving? – user7856951 Feb 27 '18 at 16:10
  • Your plane of reference would be the plane created between the two vectors, as if you projected them onto a flat surface (like your picture shows). In order to find the angle between two vectors you first have to decide the plane the angle will be in. – ryeMoss Feb 27 '18 at 16:16
  • I'm not sure i get what you mean. Could you provide a code example ? How would i determine whether i should create the vector2 from (x,y),(x,z) or (y,z), etc. ? – user7856951 Feb 27 '18 at 16:21
  • Not quickly! This is pretty involved math. I'd recommend looking at the following link or searching for something similar: [Angle between two 3d vectors](http://www.analyzemath.com/stepbystep_mathworksheets/vectors/vector3D_angle.html) – ryeMoss Feb 27 '18 at 16:34
  • I have done a lot of searching online, but i am struggling to find the answer. Tbh i have basically spent two days on this now and got pretty much zero progress. This question is a generic version of my 'actual' question here: https://stackoverflow.com/questions/49005143/leap-motion-angle-of-proximal-bone-to-metacarpal-side-to-side-movement – user7856951 Feb 27 '18 at 16:44
  • I still don't understand your problem completely. In your question you say you want the angle from top down view so you only had to look the axis(x,z) since you don't want to care for y ... Is that it or what is the angle you really want? – derHugo Feb 27 '18 at 17:49
  • I have updated the question to hopefully give a clearer explanation of the problem – user7856951 Feb 28 '18 at 11:08

1 Answers1

0

If I understand your problem correctly, you need to project your two vectors onto a plane. The vectors might not be in that plane currently (your "bent finger" problem) and thus you need to "project" them onto the plane (think of a tree casting a shadow onto the ground; the tree is the vector and the shadow is the projection onto the "plane" of the ground).

Luckily Unity3D provides a method for projection (though the math is not that hard). Vector3.ProjectOnPlane https://docs.unity3d.com/ScriptReference/Vector3.ProjectOnPlane.html

Vector3 a = ...;
Vector3 b = ...;
Vector3 planeNormal = ...;
Vector3 projectionA = Vector3.ProjectOnPlane(a, planeNormal);
Vector3 projectionB = Vector3.ProjectOnPlane(b, planeNormal);
float angle = Vector3.Angle(projectionA, projectionB);

What is unclear in your problem description is what plane you need to project onto? The horizontal plane? If so planeNormal is simply the vertical. But if it is in reference to some other transform, you will need to define that first.

avariant
  • 2,234
  • 5
  • 25
  • 33
  • i have update the question to hopefully provide clarity. I have tried using the negative of the palm normal (i.e. a normal out of the back of the hand) but the angle values change considerably when rotating the hand. – user7856951 Feb 28 '18 at 11:07
  • Based on your description, I think that the normal of the palm is exactly what you want. Yes, it does change as you rotate the hand, but the pivot point of the fingers (the upper most knuckle) remains in that plane of the palm no matter how you rotate it. – avariant Feb 28 '18 at 15:18
  • Hi, i have followed your suggestions and used 'ProjectOnPlane' with the palm normal as 'planeNormal' and it works if the fingers are straight. However, i am having an issue where, if i bend the fingers i incorrect values, which can be in the region of 160-180 degrees. – user7856951 Feb 28 '18 at 17:33
  • How are you constructing the finger vectors? Is it from first knuckle to finger tip, or is it from first knuckle to second? If it's from first to finger tip, it's possible the finger vector is pointing back toward the wrist which could result in a 180 degree angle. If you take a dot product of the two finger vectors (Vector3.Dot(a, b)) and the result is negative, the vectors are pointing in opposite directions. – avariant Feb 28 '18 at 18:21
  • It does the first knuckle to the second, then second to the third. – user7856951 Mar 01 '18 at 09:55