Blackberry Accelerometer calculations -
i'm playing "accelerometerdemo" in sdk7.0 , have question regarding calculation of "rotation" extracted xyz data.
what want accomplish have virtual "pendulum" points straight down. however, thing gyrating around , not move expect it.
here part of code:
_accchannel.getlastaccelerationdata(_xyz); double roll = mathutilities.atan2(x, z) * 180.0 / math.pi; graphics.setcolor(color.black); int xcenter = 240; int ycenter = 400; int length = 220; int newx1 = (int)(math.cos( roll ) * (double)length) - xcenter; int newy1 = (int)(math.sin( roll ) * (double)length) - ycenter; graphics.drawline(xcenter, ycenter, newx1, newy1);
any clues doing wrong?
thanks in advance!
i see @ least 2 problems:
1. math.cos() , math.sin() expect angle inputs in radians, not degrees. using code:
double roll = mathutilities.atan2(x, z) * 180.0 / math.pi;
you have converted roll
degrees.
2. secondly, subtracting center coordinates vector coordinates. believe should adding them, this:
int newx1 = (int)(math.cos( roll ) * (double)length) + xcenter; int newy1 = (int)(math.sin( roll ) * (double)length) + ycenter;
Comments
Post a Comment