math - Calculate angle between two lines (which are represent human arm) using Kinect data set in Java -
i have obtained coordinates of human shoulder, elbow , wrist using microsoft kinect device (data taken respect kinect device). while taking coordinates i'm moved arm , down. sample data set can show follows.
7/7/2015 12:02:49 shoulder x -0.06475954 shoulder y 0.266225 shoulder z 1.414332 elbow x 0.002287441 elbow y 0.03676218 elbow z 1.424792 wrist x 0.1791002 wrist y -0.06900118 wrist z 1.455758 7/7/2015 12:02:49 shoulder x -0.06655618 shoulder y 0.2654685 shoulder z 1.413007 elbow x 0.001183244 elbow y 0.0374795 elbow z 1.424512 wrist x 0.1779053 wrist y -0.06793896 wrist z 1.4554 7/7/2015 12:02:49 shoulder x -0.0703955 shoulder y 0.264899 shoulder z 1.408783 elbow x -0.001478138 elbow y 0.03802216 elbow z 1.422277 wrist x 0.1769906 wrist y -0.06481737 wrist z 1.4514
then tried calculate angle in arm in 2 conditions.
- assuming z coordinates fixed (actually above data set taken such way assumption true)
- assuming z coordinate not fixed.
i used java code calculate angles in above 2 conditions. java code follows.
import java.io.*; class main { public static void main(string args[]){ try{ fileinputstream fstream = new fileinputstream("c:\\users\\chathu\\desktop\\project code\\src\\output.txt"); datainputstream in = new datainputstream(fstream); bufferedreader br = new bufferedreader(new inputstreamreader(in)); string strline; while ((strline = br.readline()) != null) { string[] tokens = strline.split(" "); //time //shoulder cordinates double shoulderx= double.parsedouble(tokens[5]); double shouldery= double.parsedouble(tokens[8]); double shoulderz= double.parsedouble(tokens[11]); //elbow cordinates double elbowx= double.parsedouble(tokens[14]); double elbowy= double.parsedouble(tokens[17]); double elbowz= double.parsedouble(tokens[20]); //wrist cordinates double wristx= double.parsedouble(tokens[23]); double wristy= double.parsedouble(tokens[26]); double wristz= double.parsedouble(tokens[29]); //calculate angle if z fixed double m1=((shouldery-elbowy)/(shoulderx-elbowx)); double m2=((wristy-elbowy)/(wristx-elbowx)); double tanalfa=math.abs((m1-m2)/(1+(m1*m2))); system.out.println("time : "+gettimeinint(tokens[1])); system.out.println("2d angle: "+math.todegrees(math.atan(tanalfa))); //calculate andgle when z not fixed //create 2 vectors double[] u={shoulderx-elbowx,shouldery-elbowy,shoulderz-elbowz }; double[] v={wristx-elbowx,wristy-elbowy,wristz-elbowz }; double absu=math.sqrt(math.pow(u[0],2)+math.pow(u[1],2)+math.pow(u[2],2)); double absv=math.sqrt(math.pow(v[0],2)+math.pow(v[1],2)+math.pow(v[2],2)); double costheata=((dotprod(u,v))/(absu*absv)); system.out.println("3d angle: "+math.acos(costheata)); } in.close(); }catch (exception e){ system.err.println("error: " + e.getmessage()); } } public static int gettimeinint(string time){ string[] tokens = time.split(":"); int hours = integer.parseint(tokens[0]); int minutes = integer.parseint(tokens[1]); int seconds = integer.parseint(tokens[2]); int duration = 3600 * hours + 60 * minutes + seconds; return duration; } public static double dotprod(double[] a, double[] b){ if(a.length != b.length){ throw new illegalargumentexception("the dimensions have equal!"); } double sum = 0; for(int = 0; < a.length; i++){ sum += a[i] * b[i]; } return sum; } }
but when run code , check calculated angle values got totally different values under above 2 assumptions.
first 3 answers follows (answers correspond above sample data set)
time : 43369 2d angle: 42.82568606638748 3d angle: 2.3907040436551847 time : 43369 2d angle: 42.63544266854971 3d angle: 2.3947689168198463 time : 43369 2d angle: 43.151072486090776 3d angle: 2.387883634441205
can me find problem there ?
you can find angle between 2 lines cosine.
wrist = point1 elbo = point2 soulder = point3 vector1 = point1 - point2 vector2 = point1 - point3
now have vectors 1 , 2 pointing elbow wrist , shoulder respectively angle can found taking:
the arccos of ratio of dot product of these 2 vectors on product of magnitude.
for more information on math here check out this page on wikipedia
which have "3d angle..."
you cannot use atan approach because elbow angle isn't 90. if knew why looking it?
i'm not sure going "2d angle..."
Comments
Post a Comment