Reputation: 3502
I was working on a open source app of a Kinect camera , and I faced a problem while I read the source .
By the way the project idea is for controlling PowerPoint using hands, you can find the source code here.
The author uses this code:
Skeleton closestSkeleton = skeletons.Where(s => s.TrackingState == SkeletonTrackingState.Tracked)
.OrderBy(s => s.Position.Z * Math.Abs(s.Position.X))
.FirstOrDefault();
Can any one help me figure out what s => s.Position.Z * Math.Abs(s.Position.X)
means as an idea, I know it's a lambda expression so I only need to figure out why?
Upvotes: 2
Views: 131
Reputation: 9872
s => s.Position.Z * Math.Abs(s.Position.X)
is in the OrderBy statement, serving as the quantity by which to order all detected bodies. It is weighting the skeletons sort by radial distance and not just orthogonal Z separation.
Consider two objects at the same z coordinate, and the camera at the origin. The closest one is the one with a smaller horizontal (x) distance.
Upvotes: 2
Reputation: 8245
It's a distance metric, used to determine the Skeleton closest to the Kinect sensor.
In the Skeleton Space, Z is the distance from the Kinect sensor (see here).
And if you think of the room being divided in a left half and a right half, by a line from the Kinect sensor.... then X is how far away something is from that line. How far to the left or to the right.
This is also why the absolute value of X is used - the code looks how far away the Skeleton is from that hypothetical dividing line.
So this code looks how far away from the sensor a body is (Z), then multiplies it by how far to the left or right (X). It is a somewhat primitive determination of distance. (One would have expected to use the Pythagorean theorem, but maybe that was considered too slow?)
The code takes the FirstOrDefault
Skeleton, where these Skeletons are ordered by this distance metric.
Upvotes: 2