dyadica.net

Fun and Games in the Dyadic Sea

Body Mass Index

Want to be able to calculate your BMI via WiimoteLib so you can use your board ala WiiFit, heres how its done:

Before we start, for a detailed description of BMI please refer to the following Wikipedia article: http://en.wikipedia.org/wiki/Body_mass_index

The formula for calculating BMI is a simple one and can be defined as follows:

BMI = Weight in kilograms / height in meters² – Metric
BMI = (weight in pounds * 703 ) / height in inches² – Imperial

The following function is passed a WiimoteState value ws and returns BMI as a double. The division by 100 is used to convert a cm user_height value into meters and can quite easily be replaced/removed if desired. In my setup I use a trackbar so that a user can easily input their height as required

private double GetTheBodyMassIndex(WiimoteState ws)
{
double w = (double)(ws.BalanceBoardState.WeightKg);
double h = (double)(user_heght / 100);
double bmi = (double)(w) / (double)(h * h);
return bmi;
}

Simple eh! Ok what about the detailing the users Body Mass Status. Well the Wikipedia article also details the divisions of BMI which we can use to define a users BMI status. Take a look at the following function:

private string GetTheBodyMassStatus(double bmi)
{
string status = “Undefined”;
// Severely underweight: < 16.5
if (bmi < 16.5) { status = “Severely Underweight”;  }
// Underweight: 16.5 – 18.5
else if (bmi > 16.5 && bmi < 18.5) { status = “Underweight”; }
// Normal 18.5: – 25
else if (bmi > 18.5 && bmi < 25) { status = “Normal”; }
// Overweight: 25 – 30
else if (bmi > 25 && bmi < 30) { status = “Overweight”; }
// Obese Class: 1 30 – 35
else if (bmi > 30 && bmi < 35) { status = “Obese Class 1″; }
// Obese Class: 2 35 – 40
else if (bmi > 35 && bmi < 40) { status = “Obese Class 2″; }
// Obese Class: 3 > 40
else if (bmi > 40) { status = “Obese Class 3″; }
return status;
}

All we are doing here is using an if statement to filter the BMI value into the defined weight categories. The result is then returned as a string, again simple!

To call the functions just place the relevant triggers in your Wiimote Changed Event function (Mine is called UpdateWiimoteChanged) eg:

public void UpdateWiimoteChanged(WiimoteChangedEventArgs args)
{
try
{
WiimoteState ws = args.WiimoteState;
double bmi = GetTheBodyMassIndex(ws);
string status = GetTheBodyMassStatus(bmi);
}
catch (Exception ex)
{
Console.WriteLine(“Caught: ” + ex.Message.ToString());
}
}

And thats all there is to it, BMI ala WiiFit via WiimoteLib. The next stage is to build this functionality into the library itself. Please check back soon for more details!

Cats: Uncategorized

page meta

get trackback image get trackback image
details
  • Posted: Monday, 13 July '09
  • Edited: Sunday, 19 July '09
  • Author: admin
css | xhtml | dyadica.net © admin 2010 | powered: wordpress | fuel: ps-wii-elite | top | sign-up