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

#1 2010-04-24 14:13:48

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Why did this work (math question)

_x += Math.cos(Math.atan2(ship._y-this._y, .ship._x-this._x)*-1)*5
_y -= Math.sin(Math.atan2(ship._y-this._y, ship._x-this._x)*-1)*5

Why did that work?
I thought you were supposed to use sin for x and cos for y...

Not complaining, just wondering.

EDIT: BTW it's using radians

Last edited by juststickman (2010-04-24 14:14:02)


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#2 2010-04-24 14:19:49

soupoftomato
Scratcher
Registered: 2009-07-18
Posts: 1000+

Re: Why did this work (math question)

I wish I could understand some of that.


I'm glad to think that the community will always be kind and helpful, the language will always be a fun and easy way to be introduced into programming, the motto will always be: Imagine, Program, Share - Nomolos

Offline

 

#3 2010-04-24 14:21:43

BWOG
Scratcher
Registered: 2008-09-19
Posts: 1000+

Re: Why did this work (math question)

soupoftomato wrote:

I wish I could understand some of that.

Me too.

Offline

 

#4 2010-04-25 09:03:31

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Why did this work (math question)

So nobody knows?


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#5 2010-04-25 09:04:21

BWOG
Scratcher
Registered: 2008-09-19
Posts: 1000+

Re: Why did this work (math question)

Guess not.

Offline

 

#6 2010-04-25 09:04:50

waveOSBeta
Scratcher
Registered: 2009-12-08
Posts: 1000+

Re: Why did this work (math question)

Pretty much.


http://internetometer.com/image/10202.png]
New signature coming soon!  smile

Offline

 

#7 2010-04-25 09:08:58

steppenwulf
Scratcher
Registered: 2009-07-23
Posts: 1000+

Re: Why did this work (math question)

My brain has a sad after looking at that D:


I'm graduating HS this April and going to college in the Fall.

Offline

 

#8 2010-04-25 09:13:27

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Why did this work (math question)

Comeon, where did all the people past algebra go?


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#9 2010-04-25 09:16:56

BWOG
Scratcher
Registered: 2008-09-19
Posts: 1000+

Re: Why did this work (math question)

To Asia? I dunno.

Offline

 

#10 2010-04-25 09:32:27

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Why did this work (math question)

Nobody.... That's just not right...


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#11 2010-04-25 10:44:39

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

Re: Why did this work (math question)

I don't know trigonometry  sad

...but maybe scmb1 can help you

Offline

 

#12 2010-04-25 10:50:48

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Why did this work (math question)

ThePCKid wrote:

I don't know trigonometry  sad

...but maybe scmb1 can help you

Is scmb1 online?


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#13 2010-04-25 11:23:58

illusionist
Retired Community Moderator
Registered: 2008-07-02
Posts: 1000+

Re: Why did this work (math question)

If I could read that, I might be able to answer your question.  tongue


http://i.imgur.com/8LX1NrV.png

Offline

 

#14 2010-04-25 11:31:44

shamrocker
Scratcher
Registered: 2009-03-19
Posts: 1000+

Re: Why did this work (math question)

steppenwulf wrote:

My brain has a sad after looking at that D:

Ditto.


http://i46.tinypic.com/2s1b32e.png
respect the oxford comma

Offline

 

#15 2010-04-25 11:33:40

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Why did this work (math question)

illusionist wrote:

If I could read that, I might be able to answer your question.  tongue

I'll get rid of anything to do with code and just leave the equation...

x = x + cos(atan2(sy2-y1, x2-x1)*-1)*5
y = y - sin(atan2(y2-y1, x2-x1)*-1)*5


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#16 2010-04-25 11:50:40

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: Why did this work (math question)

juststickman wrote:

ThePCKid wrote:

I don't know trigonometry  sad

...but maybe scmb1 can help you

Is scmb1 online?

I am now. And, sorry, but I'm not getting anywhere with this.

I have a few questions: Are sy2, y1, y2, x1, and x2 all variables? What do they mean? What is the purpose of this equation?


http://i48.tinypic.com/2z5pqad.png

Offline

 

#17 2010-04-25 11:57:30

calebxy
Scratcher
Registered: 2009-12-31
Posts: 1000+

Re: Why did this work (math question)

I know someone who can help you. Dines. Ask him on his project. http://scratch.mit.edu/projects/Dines/999668

Or I can just ask him in real life.


I'm making my own Doctor Who series!  big_smile  See the first episode here.
And please join Story Zone!  big_smile

Offline

 

#18 2010-04-25 12:33:37

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: Why did this work (math question)

Basically, it depends on the context.

Usually, you would use radians to find x using cosine and y using sine, in a perfect circle. Interesting, isn't it?

However, most likely in your context is something not related to a perfect circle.

What are you trying to do with those equations?

I forget what atan is, but I know tangent is the ratio between sine and cosine, maybe that reverses it.


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

#19 2010-04-25 12:41:54

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Why did this work (math question)

Greatdane wrote:

Basically, it depends on the context.

Usually, you would use radians to find x using cosine and y using sine, in a perfect circle. Interesting, isn't it?

However, most likely in your context is something not related to a perfect circle.

What are you trying to do with those equations?

I forget what atan is, but I know tangent is the ratio between sine and cosine, maybe that reverses it.

here's a badly made ASCII diagram (ignore the .)
.....0<---[this is the player, x1 and y1 are its coordinates)..........
..................*<[this is an enemy, x2 and y2 are it's coordinates).
........................................................................................

I am trying to find how much x and y have to change to make the enemy move towards the player. My formula worked, but I don't know WHY it worked.


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#20 2010-04-25 17:10:42

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

Re: Why did this work (math question)

juststickman wrote:

illusionist wrote:

If I could read that, I might be able to answer your question.  tongue

I'll get rid of anything to do with code and just leave the equation...

x = x + cos(atan2(sy2-y1, x2-x1)*-1)*5
y = y - sin(atan2(y2-y1, x2-x1)*-1)*5

Okay, Let me explain this.  big_smile

Cosine and Sine (Cos and Sin) are used for finding ratios of angles. If you have a 45 degree angle (Pi/4 Radians), they are the same. At 90 Degrees (Pi/2), Cos is 0, and sin is one. Usually one multiplies this by how far the object moved to find out how far it moved in the X direction and in the Y direction. You formula looks like this. The inside gives you the angle that the object is moving. Cosine finds the ratio of that angle (x:y)
and then you multiply it by 5, the amount it moved.

I hope that helped.

Offline

 

#21 2010-04-25 17:21:52

BWOG
Scratcher
Registered: 2008-09-19
Posts: 1000+

Re: Why did this work (math question)

TheSaint wrote:

juststickman wrote:

illusionist wrote:

If I could read that, I might be able to answer your question.  tongue

I'll get rid of anything to do with code and just leave the equation...

x = x + cos(atan2(sy2-y1, x2-x1)*-1)*5
y = y - sin(atan2(y2-y1, x2-x1)*-1)*5

Okay, Let me explain this.  big_smile

Cosine and Sine (Cos and Sin) are used for finding ratios of angles. If you have a 45 degree angle (Pi/4 Radians), they are the same. At 90 Degrees (Pi/2), Cos is 0, and sin is one. Usually one multiplies this by how far the object moved to find out how far it moved in the X direction and in the Y direction. You formula looks like this. The inside gives you the angle that the object is moving. Cosine finds the ratio of that angle (x:y)
and then you multiply it by 5, the amount it moved.

I hope that helped.

That's about how far I could understand it  tongue

Offline

 

#22 2010-04-26 12:01:54

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Why did this work (math question)

TheSaint wrote:

juststickman wrote:

illusionist wrote:

If I could read that, I might be able to answer your question.  tongue

I'll get rid of anything to do with code and just leave the equation...

x = x + cos(atan2(sy2-y1, x2-x1)*-1)*5
y = y - sin(atan2(y2-y1, x2-x1)*-1)*5

Okay, Let me explain this.  big_smile

Cosine and Sine (Cos and Sin) are used for finding ratios of angles. If you have a 45 degree angle (Pi/4 Radians), they are the same. At 90 Degrees (Pi/2), Cos is 0, and sin is one. Usually one multiplies this by how far the object moved to find out how far it moved in the X direction and in the Y direction. You formula looks like this. The inside gives you the angle that the object is moving. Cosine finds the ratio of that angle (x:y)
and then you multiply it by 5, the amount it moved.

I hope that helped.

Ok, that wasn't very helpful. My question was why did it work when I reversed the sin and cos.

I used sin for Y and cos for X and it worked. And no it was not 45°.


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#23 2010-04-26 12:19:46

steppenwulf
Scratcher
Registered: 2009-07-23
Posts: 1000+

Re: Why did this work (math question)

juststickman wrote:

Comeon, where did all the people past algebra go?

I'm halfway finished with trig, but my brain still haz a sad when I look at the equation xD


I'm graduating HS this April and going to college in the Fall.

Offline

 

#24 2010-04-26 12:43:00

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Why did this work (math question)

My questions make people's brains sad  sad


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#25 2010-04-26 17:13:15

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

Re: Why did this work (math question)

juststickman wrote:

TheSaint wrote:

juststickman wrote:


I'll get rid of anything to do with code and just leave the equation...

x = x + cos(atan2(sy2-y1, x2-x1)*-1)*5
y = y - sin(atan2(y2-y1, x2-x1)*-1)*5

Okay, Let me explain this.  big_smile

Cosine and Sine (Cos and Sin) are used for finding ratios of angles. If you have a 45 degree angle (Pi/4 Radians), they are the same. At 90 Degrees (Pi/2), Cos is 0, and sin is one. Usually one multiplies this by how far the object moved to find out how far it moved in the X direction and in the Y direction. You formula looks like this. The inside gives you the angle that the object is moving. Cosine finds the ratio of that angle (x:y)
and then you multiply it by 5, the amount it moved.

I hope that helped.

Ok, that wasn't very helpful. My question was why did it work when I reversed the sin and cos.

I used sin for Y and cos for X and it worked. And no it was not 45°.

Sin is Y and Cos is X.

Offline

 

Board footer