This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-01-08 12:54:27

erbie
Scratcher
Registered: 2008-12-26
Posts: 12

new function request: atan2

In my "skeleton poser" project, I needed an atan2 function and I had to write my own (using atan and some if blocks).  atan2 is a standard function in most math libraries and is used to convert a 2d vector (dx, dy) to an angle in the full 360 degree range.  I use atan2 to rotate a sprite by clicking and dragging on it and I can't just use point-towards-mouse because the rotation is relative to the current direction as well as where the sprite was grabbed.

Having a built-in atan2 function would make my project simpler.  More importantly, it would make my sprites more portable (and understandable to other users) because the sprites wouldn't need to depend on the global atan2 script.

Offline

 

#2 2009-01-08 13:04:05

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: new function request: atan2

I would also like an atan2 function.  I second the motion.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#3 2009-01-08 20:03:33

Buddy_ca111
Scratcher
Registered: 2008-08-30
Posts: 100+

Re: new function request: atan2

What is atan2?


By reading this you agree to giving me your soul, money, passwords, projects, abiltys and your bases

Offline

 

#4 2009-01-08 20:04:35

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: new function request: atan2

Yeah, we already have some trig functions. Why not get the rest of them?


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#5 2009-01-08 21:52:22

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: new function request: atan2

Buddy_ca111 wrote:

What is atan2?

http://en.wikipedia.org/wiki/Atan2


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#6 2009-01-08 21:59:00

erbie
Scratcher
Registered: 2008-12-26
Posts: 12

Re: new function request: atan2

In a nutshell, if you have two points (call them x1,y1 and x2,y2), and you want to know what direction to go in to get from the first point to the second, atan2 will tell you:

    direction = atan2(y2-y1, x2-x1)

Last edited by erbie (2009-01-08 21:59:51)

Offline

 

#7 2009-01-08 23:19:37

Buddy_ca111
Scratcher
Registered: 2008-08-30
Posts: 100+

Re: new function request: atan2

oh ok


By reading this you agree to giving me your soul, money, passwords, projects, abiltys and your bases

Offline

 

Board footer