java - How to calculate an angle of a right triangle knowing two sides? -


i need calculate angle between 2 points in 2d space. idea calculate using right triangle? please give me formula, written in java code. thank you!

here's code:

public boolean onareatouched(touchevent pscenetouchevent,                     float ptoucharealocalx, float ptoucharealocaly) {                 double angle = math.atan2(                         ptoucharealocalx - boundspritecenterx,                         boundspritecentery - ptoucharealocaly);                 angle = math.todegrees(angle);                 log.i("egor", "angle " + angle);                 return true;             }; 

and here's i'm getting when rotate finger around sprite:

    07-21 16:07:00.736: info/egor(12600): angle -11.401802094139539 07-21 16:07:00.786: info/egor(12600): angle -11.349729213136412 07-21 16:07:00.826: info/egor(12600): angle -11.422536712363058 07-21 16:07:00.956: info/egor(12600): angle -11.234933754467884 07-21 16:07:00.986: info/egor(12600): angle -10.762776313908919 07-21 16:07:01.026: info/egor(12600): angle -10.18502866163197 07-21 16:07:01.086: info/egor(12600): angle -8.791364033967513 07-21 16:07:01.126: info/egor(12600): angle -7.51789397098733 07-21 16:07:01.266: info/egor(12600): angle -5.964822509364536 07-21 16:07:01.266: info/egor(12600): angle -3.8833834235199327 07-21 16:07:01.316: info/egor(12600): angle -3.518004982991794 07-21 16:07:01.316: info/egor(12600): angle -3.2335041547308747 07-21 16:07:01.356: info/egor(12600): angle -2.8893793853454013 07-21 16:07:01.366: info/egor(12600): angle -2.591166578194567 07-21 16:07:01.396: info/egor(12600): angle -2.4890755982704613 07-21 16:07:01.426: info/egor(12600): angle -2.4041628132172432 07-21 16:07:01.466: info/egor(12600): angle -2.606754218788734 07-21 16:07:01.486: info/egor(12600): angle -2.9585030905373477 07-21 16:07:01.516: info/egor(12600): angle -3.203094764102693 07-21 16:07:01.546: info/egor(12600): angle -4.143849229994 07-21 16:07:01.576: info/egor(12600): angle -4.833402961115934 07-21 16:07:01.596: info/egor(12600): angle -5.201363076921709 07-21 16:07:01.626: info/egor(12600): angle -7.182189581196999 07-21 16:07:01.666: info/egor(12600): angle -8.30009901770206 07-21 16:07:01.706: info/egor(12600): angle -10.305907456087617 07-21 16:07:01.746: info/egor(12600): angle -11.845396664651743 07-21 16:07:01.776: info/egor(12600): angle -13.486956315730428 07-21 16:07:01.796: info/egor(12600): angle -14.928485252180119 07-21 16:07:01.826: info/egor(12600): angle -15.930527466185383 07-21 16:07:01.856: info/egor(12600): angle -17.523214080867536 07-21 16:07:01.876: info/egor(12600): angle -18.670097079838413 07-21 16:07:01.906: info/egor(12600): angle -19.784066963586145 07-21 16:07:01.946: info/egor(12600): angle -20.967697211428263 07-21 16:07:01.966: info/egor(12600): angle -22.839177072269344 07-21 16:07:01.986: info/egor(12600): angle -23.995902815112903 07-21 16:07:02.026: info/egor(12600): angle -24.94729858380699 07-21 16:07:02.046: info/egor(12600): angle -25.824795978977953 07-21 16:07:02.066: info/egor(12600): angle -26.163619752371858 07-21 16:07:02.106: info/egor(12600): angle -27.036651116353283 07-21 16:07:02.126: info/egor(12600): angle -27.392238974828167 07-21 16:07:02.266: info/egor(12600): angle -28.076676644069305 07-21 16:07:02.276: info/egor(12600): angle -28.49774854622218 07-21 16:07:02.316: info/egor(12600): angle -28.408406568602896 07-21 16:07:02.316: info/egor(12600): angle -28.323322872571392 07-21 16:07:02.356: info/egor(12600): angle -28.24684157963425 07-21 16:07:02.366: info/egor(12600): angle -28.115274003009183 07-21 16:07:02.406: info/egor(12600): angle -27.97540955255425 07-21 16:07:02.426: info/egor(12600): angle -27.947947494965728 07-21 16:07:02.446: info/egor(12600): angle -27.908408445343735 07-21 16:07:02.486: info/egor(12600): angle -27.621472392453533 07-21 16:07:02.506: info/egor(12600): angle -27.31775291690124 07-21 16:07:02.526: info/egor(12600): angle -26.84707894871403 07-21 16:07:02.556: info/egor(12600): angle -26.573497423338885 07-21 16:07:02.586: info/egor(12600): angle -25.553344674326492 07-21 16:07:02.606: info/egor(12600): angle -24.681035396816615 07-21 16:07:02.646: info/egor(12600): angle -23.164315738891876 07-21 16:07:02.686: info/egor(12600): angle -22.001937944957152 07-21 16:07:02.696: info/egor(12600): angle -21.108728821882377 07-21 16:07:02.726: info/egor(12600): angle -20.777362892583056 07-21 16:07:02.756: info/egor(12600): angle -20.331914563591184 07-21 16:07:02.776: info/egor(12600): angle -19.842422968714942 07-21 16:07:02.796: info/egor(12600): angle -18.943202330016586 07-21 16:07:02.836: info/egor(12600): angle -17.900217339627066 07-21 16:07:02.886: info/egor(12600): angle -16.38438849186955 07-21 16:07:02.896: info/egor(12600): angle -15.49309440885704 07-21 16:07:02.916: info/egor(12600): angle -14.663361857753415 07-21 16:07:02.956: info/egor(12600): angle -14.06291160310325 07-21 16:07:02.976: info/egor(12600): angle -13.743513115207124 07-21 16:07:02.996: info/egor(12600): angle -13.436847871994882 07-21 16:07:03.076: info/egor(12600): angle -13.436847871994882 

in screen coordinates (where origin @ top left , y increases downwards) if centre of image (x0,y0) , "finger" @ (xa,ya) angle require is

math.atan2(xa-x0,y0-ya) 

this give angle in radians have rotate image clockwise starting position.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -