Saturday, 15 January 2011

kinect toolbox c# syntax -



kinect toolbox c# syntax -

i have been studying algorithm used in kinect toolbox compare vector sequences, struggling understand piece of code:

public static float distanceto(this list<vector2> path1, list<vector2> path2) { homecoming path1.select((t, i) => (t - path2[i]).length).average(); }

as far understand takes 2 sequences of 2d vectors , computes distance between them means of euclidean distance, is, calculates length of difference between vectors, had never seen syntax within parenthesis, specially =>.

any insight much appreciated.

you can unroll select statement.

path1.select((t, i) => (t - path2[i]).length) iterates on path1, every element in it, selects vector2 element , index in path1 list.

from intermediate result difference between 2 corresponding vectors @ same index (t - path2[i]), - parameter overload vector substraction method. difference calculate vector length squared(?) addition on elements.

average() in end takes average on given vector differences.

this c# code semantically same:

float sum = 0.0f; for(int = 0; < path1.count; i++) { sum += (path1[i] - path[2]).length; } homecoming sum / (float)path1.count;

or nicer linq zip expression:

path1.zip(path2, (left, right) => (left-right).length).average();

c# kinect toolbox

No comments:

Post a Comment