Angle Reader For Phun Beta 5
7 posts • Page 1 of 1
Angle Reader For Phun Beta 5
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
-
niffirg1 - Posts: 376
- Joined: Mon Aug 31, 2009 10:31 pm
- Location: The Great American South!
Re: Angle Reader For Phun Beta 5
- 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.
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: Angle Reader For Phun Beta 5
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:
For the angle in degrees:
If you want to display the angle of e.normal just type in this to OnCollide, OnLaserHit or OnHitByLaser:
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)}}
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: Angle Reader For Phun Beta 5
The excellent K-Probe from Killinich:
http://www.algodoo.com/algobox/details.php?id=23923
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
Yes i have checked there but that is not really what i am looking for
-
niffirg1 - Posts: 376
- Joined: Mon Aug 31, 2009 10:31 pm
- Location: The Great American South!
Re: Angle Reader For Phun Beta 5
Then what exactly are you looking for? You can use either ofthe scripts we posted and update them with beacons.
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: Angle Reader For Phun Beta 5
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...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
7 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 5 guests