I am trying to design graphics based on the pitch and roll value using 'C'. for that i have a tilt sensor (accelerometer) which spits out the roll and pitch value. I want to make use of a graphics which should be able to show me the direction in which i tilt the tilt sensor.
Below is some code from my program which determines the angle ( based on pitch and roll value).
szBuff[] having data in R:SXXX.XX P:SXXX.XX\r\n format
where S= sign and R= roll, P= pitch.
if (szBuff[2] == '+' && szBuff[12] == '-')
{
-------------------------------------
if(pitch>roll){
Angle = atan(pitch / pitch- roll); // Insert formula here
-------------------------------------
}
}
Here pitch and roll are without sign.
I draw a line which deflects based on the pitch and roll value. Using above algorithm i calculate the Angle with which it has to deflect.
line((left+150),(top+150),((left+150)+150*cos(Angle)),((top+150)+150*sin(Angle)));
I need a mathematical equation which could fulfill my objective. Angle = atan(pitch / pitch -roll) doesn't draw the required angle. Only for same pitch and roll it holds true and throws 90 degree( which means i am tilting the sensor in forward direction). So could you please replace the Angle formula with some mathematical expression which could generate the tilting angle based on roll and pitch.
I have attached screen shot of output. If you find my question ambiguous then please excuse and suggest for betterment of question so that i get it answered.
Usually, pitch and roll are angles. I assume that roll is the angle which rotates about the vertical axis and pitch is the angle which rotates about the horizontal axis.
Then you can calculate the 3d position as:
Both
roll
andpitch
should contain their signs.It seems that you want to project this vector on a fixed plane, probably the xz-plane. Then you would draw this using: