Angle Reader For Phun Beta 5

About advanced scenes, and the Thyme scripting language used in Algodoo.

Angle Reader For Phun Beta 5

Postby niffirg1 » Thu Nov 19, 2009 3:51 am

Is there an accurate angle reader that is for Phun. I tried to make my own but it was a complete fail. Or just what is the code for this. I tried using math.acos But i did not work due to the lack of knowledge on Math. Coding
User avatar
niffirg1
 
Posts: 376
Joined: Mon Aug 31, 2009 10:31 pm
Location: The Great American South!

Re: Angle Reader For Phun Beta 5

Postby standardtoaster » Thu Nov 19, 2009 4:59 am

Code: Select all
    Scene.my.atan2=(P1, P2)=>{2 * math.atan((P2(1)-P1(1)) / (((((P2(0)-P1(0))^2) + (P2(1)-P1(1))^2) ^ 0.5) + (P2(0)-P1(0))))}

How's that? Give it two points and it will tell you the angle in radians.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: Angle Reader For Phun Beta 5

Postby KarateBrot » Thu Nov 19, 2009 6:12 am

atan2 tells angles in one direction to 180° and in the other direction to -180° but between 180° and -180° there's a gap in the definition and "NaN" will be displayed.

With the cosine you can display the absolute angle from 0° to 360°.

For the angle in radians:
Code: Select all
Scene.my.angle = (p1,p2) => { angle := math.acos((p2(0) - p1(0)) / ((p2(0) - p1(0))^2 + (p2(1) - p1(1))^2)^0.5); (p2(1) - p1(1)) < 0 ? {angle = 2*math.pi - angle} : {}; angle }


For the angle in degrees:
Code: Select all
Scene.my.angle = (p1,p2) => { angle := math.acos((p2(0) - p1(0)) / ((p2(0) - p1(0))^2 + (p2(1) - p1(1))^2)^0.5) * 180 / math.pi; (p2(1) - p1(1)) < 0 ? {angle = 360 - angle} : {}; angle }


If you want to display the angle of e.normal just type in this to OnCollide, OnLaserHit or OnHitByLaser:
Code: Select all
(e)=>{text = {"" + scene.my.angle([0, 0], e.normal)}}
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Angle Reader For Phun Beta 5

Postby Antotabo » Tue Nov 24, 2009 4:29 am

The excellent K-Probe from Killinich:
http://www.algodoo.com/algobox/details.php?id=23923
Antotabo
 
Posts: 54
Joined: Tue Sep 01, 2009 6:27 am

Re: Angle Reader For Phun Beta 5

Postby niffirg1 » Tue Nov 24, 2009 6:42 am

Yes i have checked there but that is not really what i am looking for
User avatar
niffirg1
 
Posts: 376
Joined: Mon Aug 31, 2009 10:31 pm
Location: The Great American South!

Re: Angle Reader For Phun Beta 5

Postby standardtoaster » Tue Nov 24, 2009 7:31 am

Then what exactly are you looking for? You can use either ofthe scripts we posted and update them with beacons. :|
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: Angle Reader For Phun Beta 5

Postby Kilinich » Tue Nov 24, 2009 9:45 am

niffirg1 wrote:Is there an accurate angle reader that is for Phun. I tried to make my own but it was a complete fail. Or just what is the code for this. I tried using math.acos But i did not work due to the lack of knowledge on Math. Coding

Just pick K-Probe and use scene.my.k1angle variable.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 2 guests