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

#1 2008-11-09 16:38:59

TheSaint
Scratcher
Registered: 2008-11-04
Posts: 1000+

Some trig help.

I need some help coming up with a formula that:
Will set an x postion according to an angle so say

Angle=50,90 and 40. The sprite is at the 50 angle, or at the top. I can get the y postion. Anyway to tell where it needs to be so it always goes to the right x postion?
                                         
                                               Sprite 1
                                                      :
                                                   :  :
                                                 :50:
                                               :      :
                              Unkown  :        :  Y of (sprite 1) - Y of (Sprite 2)
                                         :            :
                                     :                :
                                :40            90:
                                 *****************
                                          X(Also Unknown)

What I basically want is a formula that positions sprite one so it is always at this ratio thingy from sprite one.

Offline

 

#2 2008-11-09 17:28:11

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

Re: Some trig help.

The tangent of the 40 degree angle is the ratio of the perpendicular sides of the right triangle so

                                         [(Y of Sprite 1) - (Y of Sprite 2)]
                     tangent 40 =  --------------------------------------------
                                         [(X of Sprite 1) - (X of Sprite 2)]

So, you can then solve for what you want

X of Sprite 1 = (X of Sprite 2) + [(Y of Sprite 1) - (Y of Sprite 2)} / tangent 40

Note:  Because Scratch uses an odd definition of zero degrees (straight up) which differs from the usual math book definition (zero degrees is off to the right),  I might have screwed this up a little...if it doesn't work, try switching the roles of X and Y.  Sorry I can't do any better right now, gotta run!


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

Offline

 

#3 2008-11-09 17:41:20

TheSaint
Scratcher
Registered: 2008-11-04
Posts: 1000+

Re: Some trig help.

Thanks Man! That is exactly what I was looking for and it works pretty well. One question though. When did you join the scratch team?

Offline

 

#4 2008-11-09 20:39:10

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

Re: Some trig help.

TheSaint wrote:

Thanks Man! That is exactly what I was looking for and it works pretty well. One question though. When did you join the scratch team?

Well, look at that!  I wasn't aware that I had joined the team.  Thanks for pointing it out.  I'm not sure why my title is showing up that way...


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

Offline

 

Board footer