GMU:Tutorials/Performance Platform/Measuring Motion with Processing: Difference between revisions

From Medien Wiki
No edit summary
No edit summary
Line 93: Line 93:
     background(speed);  
     background(speed);  
</source>
</source>
== Enjoy and keep on ==

Revision as of 21:02, 31 July 2016

Measuring Motion

measuring motion


Introduction:

Through the motion tracking system man could get basic information about one or more persons’ movements in the specific area. Normally these information describe the status of some important nodes of a person, such as head, arms, hip, feet and so on.
This article is mainly a step by step tutorial about different ways of accumulating motion data(such as the speed of a person or the expansion among three persons) into a single value. In the following examples, these simple values are visualised in a simple basic way in processing: changing the background color.

Preparations:

Challenges:

  • One person mode: Calculating the root speed and visualizing this value by changing the background color.
  • Groups of persons mode: Measuring the pairwise distances between root nodes of three persons.

Process:

1. Collecting the correlative data for the speed: Through the connecting of OSC and Motion Tracking platform, the root position and the updated data of one person could be obtained. The shifting distance and the relevant time decides the speed of the root node.

public void updateRoot(float x, float y, float z) {    
    x2 = abs(x - x1);
    y2 = abs(y - y1);
    z2 = abs(z - z1);
    
    x1 = this.x;
    y1 = this.y;
    z1 = this.z;
   float distance = sqrt(sq(x2)+sq(y2)+sq(z2));
   //Record the duration time that this bone move from the first point to the second point
   temptime = millis();
   time2 = (temptime - time1)/1000;
    //Calculate the velocity of this bone
    vel = (distance/time2)*100;
  }

2. The shifting distance and the relevant time decides the speed of the root node.

float speed (Sphere sphere1)
{
  float vel2 = sphere1.vel-vel1;
  vel1 = sphere1.vel;
  return vel2;
}

3.Calculating the distance between two root points.

float distance (Sphere sphere1,Sphere sphere2)
{
    float distance = sqrt(sq(sphere1.x-sphere2.x)+sq(sphere1.y-sphere2.y)+sq(sphere1.z-sphere2.z));
    float dis2;
    dis2 = distance;
    distance = distance-dis1;
    dis1 = dis2;
    return distance;
}

4.Calculating the area of the triangle make up by three root points.

float triangleSize(Sphere sphere1,Sphere sphere2,Sphere sphere3)
  {
    float side_a = sqrt(sq(sphere1.x-sphere2.x)+sq(sphere1.y-sphere2.y)+sq(sphere1.z-sphere2.z));
    float side_b = sqrt(sq(sphere1.x-sphere3.x)+sq(sphere1.y-sphere3.y)+sq(sphere1.z-sphere3.z));
    float side_c = sqrt(sq(sphere2.x-sphere3.x)+sq(sphere2.y-sphere3.y)+sq(sphere2.z-sphere3.z));
    float s = (side_a+side_b+side_c)/2;
    float triangleSize = sqrt(s*(s-side_a)*(s-side_b)*(s-side_c));
    float size2;
    size2 = triangleSize;
    triangleSize = triangleSize-size1; 
    size1 = size2;
    return triangleSize;
  }

Three root positions could form a triangle in the space. With the help of Heron’s formula, the area of the triangle could be calculated.

5.According to the speed, distance, area giving different background color.

//the maximum area is 6*6/2=18m^2,mapping the value of the area to the color of the background
    float size = triangleSize(sphere1,sphere2,sphere3);
    size = map(size,0,18,0,255);
    size = ceil(size);
    background(size); 

//the maximum distance is 6m,mapping the value of the distance to the color of the background
    float dis = ditance(sphere1,sphere2);
    dis = map(dis,0,6,0,255);
    dis = ceil(dis);
    background(dis); 

//the maximum speed of human is 10m/s,mapping the value of the speed to the color of the background
    float speed = speed(sphere1);
    speed = map(speed,0,10,0,255);
    speed = ceil(speed);
    background(speed);

Enjoy and keep on