title: Calculating Center of mass of body being tracked using kinect?
body: <p>I am working on Kinect for my research project . I have worked previously to calculate the joint angle of kinect and the joint coordinates. I would like to calculate the center of mass of the body which is being tracked. 
  Any idea would be appreciated and code snippets would be immensely helpful.
  I owe a lot to stack overflow without the community help it would had not been possible to do such a thing.
  Thanks in Advance 
  Please find the code where i want to include this center of mass function. This function tracks the skeleton.</p>
  
  <p>Skeleton GetFirstSkeleton(AllFramesReadyEventArgs e)
          {
              using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame())
              {
                  if (skeletonFrameData == null)
                  {
                      return null;
                  }</p>
  
  <pre><code>            skeletonFrameData.CopySkeletonDataTo(allSkeletons);
  
              //get the first tracked skeleton
              Skeleton first = (from s in allSkeletons
                                where s.TrackingState == SkeletonTrackingState.Tracked
                                select s).FirstOrDefault();
              return first;
          }
  </code></pre>
  
  <p>I have tried using this code in my code but its not getting accustomed , can any one please help me include the center of mass code.</p>
  
  <p>oreach (SkeletonData data in skeletonFrame.Skeletons) {</p>
  
  <p>SkeletonFrame allskeleton = e.SkeletonFrame;</p>
  
  <pre><code>            // Count passive and active person up to six in the group  
  
              int numberOfSkeletonsT = (from s in allskeleton.Skeletons
  
                                        where s.TrackingState == SkeletonTrackingState.Tracked  select s).Count();
  
              int numberOfSkeletonsP = (from s in allskeleton.Skeletons  
  </code></pre>
  
  <p>where s.TrackingState == SkeletonTrackingState.PositionOnly select s).Count();</p>
  
  <pre><code>            // Count passive and active person up to six in the group
  
              int totalSkeletons = numberOfSkeletonsP + numberOfSkeletonsT;
  
              //Console.WriteLine("TotalSkeletons = " + totalSkeletons);
  </code></pre>
  
  <p>//======================================================</p>
  
  <p>if (data.TrackingState == SkeletonTrackingState.PositionOnly)</p>
  
  <pre><code>            {
  </code></pre>
  
  <p>foreach (Joint joint in data.Joints)</p>
  
  <pre><code>                {
  
                      if (joint.Position.Z != 0)
  
                      {
  
  double centerofmassX = com.Position.X;
  
                          double centerofmassY = com.Position.Y;
  
                          double centerofmassZ = com.Position.Z;
  
     Console.WriteLine( centerofmassX +  centerofmassY + centerofmassZ );
  
                      }
  
              }
  </code></pre>