On Thursday, September 27, 2012 11:27:46 AM UTC-7, Lew wrote: > > bob wrote: > >> So, I'm trying to learn how to make an android [sic] compass. >> >> Naturally, I used a site called google and typed the following in: >> >> "making an android compass" >> >> I found myself at this URL: >> >> >> http://android-er.blogspot.com/2010/08/simple-compass-sensormanager-and.html >> >> After looking thru it, I'm thinking it's incorrect. >> >> > You are mistaken. > > >> There is this suspiciously simple method: >> >> > What does "suspiciously simple" even mean? > > Why should simplicity engender suspicion? > > It's obviously a cover method for one that is less "suspicious". > > >> public void onSensorChanged(SensorEvent event) { >> // TODO Auto-generated method stub >> myCompassView.updateDirection((float)event.values[0]); >> } >> >> >> Basically, it seems like they are using the x component of the force >> vector as if it were an angle. Can someone else look at this and let me >> know what you think? >> >> > I think, no, wait, I am certain because I read the code to which you > linked that it uses the x component > to calculate the angle. > > It's trigonometry. I know, it must seem like magic. > > From the site to which you linked: > > canvas.drawLine(cxCompass, cyCompass, > (float)(cxCompass + radiusCompass * Math.sin((double)(-direction) * > 3.14/180)), > (float)(cyCompass - radiusCompass * Math.cos((double)(-direction) * > 3.14/180)), > paint); > > > I think I might've used > http://developer.android.com/reference/java/lang/Math.html#PI > and predefined > > private static final double CONVERT = Math.PI / 180.0; > > I'm sorry, I made a mistake. I said, "uses the x component to calculate the angle" and should have said, "uses the angle to calculate the x component".
See http://developer.android.com/guide/topics/sensors/sensors_position.html -- Lew -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en