This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.
  • Index
  •  » FAQ
  •  » how do I use sin. cos, and tan?

#26 2008-05-18 21:11:54

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: how do I use sin. cos, and tan?

For a very simple way to remember right triangle trig, just remember the phrase "SOHCAHTOA" (s=o/h, c=a/h, t=o/a), where s is sine, c is cosine, and t is tangent. O stands for opposite (opposite side or angle), h stands for hypotenuse, and a stands for adjacent (side length). To do any of this, you need to have 3 things defined. You need to have the unknown (SCT) and 2 knowns (OAH). Just solve it like any basic algebraic equation then! By the way, if you are solving for certain values using this, you might need a trig table. Or if you have a graphing calculator, just input the problem in, and it will solve it for you.


All your base are belong to us

Offline

 

#27 2008-05-18 23:21:01

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

Re: how do I use sin. cos, and tan?

Cyclone103 wrote:

For a very simple way to remember right triangle trig, just remember the phrase "SOHCAHTOA" (s=o/h, c=a/h, t=o/a), where s is sine, c is cosine, and t is tangent. O stands for opposite (opposite side or angle), h stands for hypotenuse, and a stands for adjacent (side length). To do any of this, you need to have 3 things defined. You need to have the unknown (SCT) and 2 knowns (OAH). Just solve it like any basic algebraic equation then! By the way, if you are solving for certain values using this, you might need a trig table. Or if you have a graphing calculator, just input the problem in, and it will solve it for you.

My teacher told me about SOHCAHTOA too  smile


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

 

#28 2008-05-19 06:05:34

Bobby500
Scratcher
Registered: 2008-04-19
Posts: 1000+

Re: how do I use sin. cos, and tan?

Same here.

Offline

 

#29 2008-05-19 16:14:18

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: how do I use sin. cos, and tan?

SOHCAHTOA was the only way that I was able to remember right triangle trig. I probably never would have remembered it otherwise (^_^)


All your base are belong to us

Offline

 

#30 2008-05-19 16:28:47

Bobby500
Scratcher
Registered: 2008-04-19
Posts: 1000+

Re: how do I use sin. cos, and tan?

I know. I missed the lesson because I was sick and I had to retake the test because I got a 30 on it. Luckly, I had an awsome math teacher.

Offline

 

#31 2008-05-19 19:05:49

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: how do I use sin. cos, and tan?

lol my teacher was so good, that when I missed 9 days of school, the unit test was right after that and I had missed some pretty important stuff, but then I aced the test  smile


All your base are belong to us

Offline

 

#32 2008-08-02 23:18:05

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: how do I use sin. cos, and tan?

Hm... after reading the lesson that Archmage gave several times, I sort of understand Sine, Cosine and Tangent. One thing I do NOT get, however, is how to use it in a game. Paddle2See's explanation didn't really help, I thought trigonometry was for right triangles? I don't see how exactly it works in a game, though I do see the effect of it. Wait... I somewhat understand. Could it be used for determining velocities for sprites that change direction, but still keep going in the direction they were thrust in after turning? Also...

dingdong wrote:

I'm probably the youngest "good" scratcher on this website, oh yeah I learned scrolling in steps from you, so thanx

No need to brag, dingdong. For all we know,  there could be a genious three-year-old Scratcher better than Paddle2See out there. So never assume you're the best of your age, never think you're better than anyone else. We're all the best in our own special way.

Offline

 

#33 2008-08-02 23:30:25

Bluestribute
Scratcher
Registered: 2008-01-24
Posts: 1000+

Re: how do I use sin. cos, and tan?

coolstuff wrote:

Hm... after reading the lesson that Archmage gave several times, I sort of understand Sine, Cosine and Tangent. One thing I do NOT get, however, is how to use it in a game. Paddle2See's explanation didn't really help, I thought trigonometry was for right triangles? I don't see how exactly it works in a game, though I do see the effect of it. Wait... I somewhat understand. Could it be used for determining velocities for sprites that change direction, but still keep going in the direction they were thrust in after turning? Also...

dingdong wrote:

I'm probably the youngest "good" scratcher on this website, oh yeah I learned scrolling in steps from you, so thanx

No need to brag, dingdong. For all we know,  there could be a genious three-year-old Scratcher better than Paddle2See out there. So never assume you're the best of your age, never think you're better than anyone else. We're all the best in our own special way.

We already talked about this coolstuff on a different post. Remember?


http://img247.imageshack.us/img247/1204/bluestributett4.jpg
That's my PSN ID. I know tons of COD4 glitches. Add me as your friend. Oh, and get a headset

Offline

 

#34 2008-08-03 01:00:40

forcemaster
Scratcher
Registered: 2007-11-17
Posts: 42

Re: how do I use sin. cos, and tan?

piplupquaza wrote:

dingdong wrote:

I'm probably the youngest "good" scratcher on this website, oh yeah I learned scrolling in steps from you, so thanx

How old are u then? just wondering PS im 11<next costume>

dingdong is 13


Go Gray Bear Productions!  smile

Offline

 

#35 2008-08-03 01:02:36

forcemaster
Scratcher
Registered: 2007-11-17
Posts: 42

Re: how do I use sin. cos, and tan?

Archmage: That's a good explanation. I don't know trig, but my sister Robin7 (she's 13, and going into 9th grade, because she skipped a grade) does know some.


Go Gray Bear Productions!  smile

Offline

 

#36 2008-08-03 09:44:22

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: how do I use sin. cos, and tan?

Bluestribute wrote:

coolstuff wrote:

Hm... after reading the lesson that Archmage gave several times, I sort of understand Sine, Cosine and Tangent. One thing I do NOT get, however, is how to use it in a game. Paddle2See's explanation didn't really help, I thought trigonometry was for right triangles? I don't see how exactly it works in a game, though I do see the effect of it. Wait... I somewhat understand. Could it be used for determining velocities for sprites that change direction, but still keep going in the direction they were thrust in after turning? Also...

dingdong wrote:

I'm probably the youngest "good" scratcher on this website, oh yeah I learned scrolling in steps from you, so thanx

No need to brag, dingdong. For all we know,  there could be a genious three-year-old Scratcher better than Paddle2See out there. So never assume you're the best of your age, never think you're better than anyone else. We're all the best in our own special way.

We already talked about this coolstuff on a different post. Remember?

no...
And if you mean by Paddle2See's explanation, I said that I didn't quite get that.

Offline

 

#37 2008-08-04 09:38:50

SonicPopsDad
Scratcher
Registered: 2008-07-30
Posts: 41

Re: how do I use sin. cos, and tan?

I've just started messing about with this stuff (with the usual aim of making a nice Asteroids style space ship, with vectored thrust), but I have to admit my maths is bloomin' awful  smile   I was never very good at it at school, and that was a long time ago too... so this is a bit of a struggle for me!

I got the computation to work in a spreadsheet... I think.  I have two questions:

1) Taking Y axis thrust as an example, my expected results were:  for direction 0, I should get, say, 10 units of thrust.  For direction 90 I should get 0 thrust, for -180 I should get -10.  My current algorithm returns those figures.
But I also expected to get 5 for direction 45.  But I don't.  I get 5 for direction 30 (or was it 60?).  Is that right?  Or have I messed up the algorithm?

(I'll post my algorithm when I get home, I can't remember exactly what it is)
edit: just worked it out...

where col A contains the angle, and D1 is =SUM(3.14159265/180) (for radian conversion)
=SUM(SIN(A1*D1))

2) When I apply it to my Scratch project, it seems the engine is resorting to integers somewhere in the calculation, as I only seem to get thrust values of zero or 10  sad   Obviously I could just have messed up the calculation, but are there any problems with precision / rounding I should be aware of?


cheers  smile

Last edited by SonicPopsDad (2008-08-04 10:24:06)

Offline

 

#38 2008-08-04 10:33:49

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

Re: how do I use sin. cos, and tan?

SonicPopsDad wrote:

I've just started messing about with this stuff (with the usual aim of making a nice Asteroids style space ship, with vectored thrust), but I have to admit my maths is bloomin' awful  smile   I was never very good at it at school, and that was a long time ago too... so this is a bit of a struggle for me!

I got the computation to work in a spreadsheet... I think.  I have two questions:

1) Taking Y axis thrust as an example, my expected results were:  for direction 0, I should get, say, 10 units of thrust.  For direction 90 I should get 0 thrust, for -180 I should get -10.  My current algorithm returns those figures.
But I also expected to get 5 for direction 45.  But I don't.  I get 5 for direction 30 (or was it 60?).  Is that right?  Or have I messed up the algorithm?

(I'll post my algorithm when I get home, I can't remember exactly what it is)
edit: just worked it out...

where col A contains the angle, and D1 is =SUM(3.14159265/180) (for radian conversion)
=SUM(SIN(A1*D1))

2) When I apply it to my Scratch project, it seems the engine is resorting to integers somewhere in the calculation, as I only seem to get thrust values of zero or 10  sad   Obviously I could just have messed up the calculation, but are there any problems with precision / rounding I should be aware of?


cheers  smile

Okay...a couple of things.  If you are getting 10 units of thrust at zero degrees, you should be getting -10 units at 180 degrees and -180 degrees (both are the same direction).  You should be using an expression similar to:

            Y_thrust = 10 * Cos(direction)
            X_thrust = 10 * Sin(direction)

At 45 degrees, you should be getting about 7.07 units for both Y_thrust and X_thrust.  Remember that the pythagorian formula is used to get the total magnitude of a vector from it's components so the square root of (7.07^2 + 7.07^2) = 10.  At 60 degrees you should be getting 5 units. 

There is no need to mess around with radians, all the Scratch functions work in degrees.  You should not be getting round-off but you may find that the Say function will only report values to the nearest tenth.  The precision is still kept internally.  Hope that helps!


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

Offline

 

#39 2008-08-04 10:46:45

SonicPopsDad
Scratcher
Registered: 2008-07-30
Posts: 41

Re: how do I use sin. cos, and tan?

Thanks Paddle2see, for the purposes of my example I'd ignored direction, but hadn't in my Scratch code. But I hadn't really thought it through and so I think your maths makes for a much more elegant answer to the problem than I'd written so far!

Offline

 

#40 2008-08-04 12:01:43

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

Re: how do I use sin. cos, and tan?

SonicPopsDad wrote:

Thanks Paddle2see, for the purposes of my example I'd ignored direction, but hadn't in my Scratch code. But I hadn't really thought it through and so I think your maths makes for a much more elegant answer to the problem than I'd written so far!

No problem.  Always eager to help another Asteroids fan!  I have a gallery of Asteroid games if you want to see what others have done.   Of course, sometimes its more fun just to do it yourself!


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

Offline

 

#41 2008-08-04 14:43:14

SonicPopsDad
Scratcher
Registered: 2008-07-30
Posts: 41

Re: how do I use sin. cos, and tan?

No problem.  Always eager to help another Asteroids fan!  I have a gallery of Asteroid games if you want to see what others have done.   Of course, sometimes its more fun just to do it yourself!

I've seen there are a few Asteroid games, so I'm trying to make Space Castle!
And yes, I'm trying to work it out *mostly* for myself.  At work of course we eschew 'reinventing the wheel' to save time, but here it's really the intellectual exercise that makes it really worthwhile  smile   
Having said that, I also started to work out a method of doing scrolling, got a bit bogged down and so took a look at Archmage's method.  His method coincides closely to my attempt, but he's already worked out the bugs... I'm going to use his code.  I think the same may occur with the Asteroids ship!


edit:  Actually it wasn't too tricky... and quite fun fiddling the scaling figures on the thrust vectors to get the right 'feel' to the spaceship movement.  I've still got some gameplay tweaks to do, but it's nearly in a shareable form  smile   Oh, and you may know the game as 'Star Castle' not Space Castle  wink

Last edited by SonicPopsDad (2008-08-05 11:47:54)

Offline

 

#42 2009-01-18 17:16:03

Jello715
Scratcher
Registered: 2008-10-11
Posts: 95

Re: how do I use sin. cos, and tan?

dingdong wrote:

I'm probably the youngest "good" scratcher on this website, oh yeah I learned scrolling in steps from you, so thanx

What's that supposed to mean?

I'm 12, and that means I'm younger than you. So you're saying that everyone younger than you isn't good at Scratch? At least I'm not the one asking how to use the trig functions XP

Offline

 

#43 2009-01-18 17:31:42

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

Re: how do I use sin. cos, and tan?

Jello715 wrote:

dingdong wrote:

I'm probably the youngest "good" scratcher on this website, oh yeah I learned scrolling in steps from you, so thanx

What's that supposed to mean?

I'm 12, and that means I'm younger than you. So you're saying that everyone younger than you isn't good at Scratch? At least I'm not the one asking how to use the trig functions XP

I think that Dingdong's ego just got the best of him  tongue

Programming skill is also very dependent on age as well. Older scratchers will have a much easier time creating things. If you can create anything at 12 years old then I would say that you are good  smile

Last edited by archmage (2009-01-18 17:32:54)


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

 

#44 2009-01-20 17:10:55

726961
Scratcher
Registered: 2008-11-26
Posts: 100+

Re: how do I use sin. cos, and tan?

dingdong wrote:

I'm probably the youngest "good" scratcher on this website, oh yeah I learned scrolling in steps from you, so thanx

were the same age, and I consider myself a "good" scratcher also, but there are younger scratchers who could out game me.


http://scratch.mit.edu/projects/726961/604658 play it now! or else...

Offline

 

#45 2009-03-10 10:01:43

Targethero
Scratcher
Registered: 2008-09-08
Posts: 1000+

Re: how do I use sin. cos, and tan?

dingdong wrote:

I'm probably the youngest "good" scratcher on this website, oh yeah I learned scrolling in steps from you, so thanx

Hey, I'm 13 and I am a great scratcher  cool


http://img97.imageshack.us/img97/3981/targethero2.png http://ls.gd/bo

Offline

 

#46 2009-03-20 10:50:54

qpalzm
Scratcher
Registered: 2008-05-18
Posts: 1

Re: how do I use sin. cos, and tan?

sin is without in spanish

Offline

 

#47 2009-03-20 12:32:04

yambanshee
Scratcher
Registered: 2007-11-06
Posts: 500+

Re: how do I use sin. cos, and tan?

hmmm, i recently did this in maths, so ill explain how i learnt it.
we use SOHCAHTOA.
break down is this:
SOH: Sin Opposite/hypotenuse
CAH: Cosin Adjacent/hypotenuse
TOA: Tan Opposite/adjacent.
http://i245.photobucket.com/albums/gg70/yambanshee/Trigtriangle.jpg

Lets say you wanted to work out what X is.
the adjacent is ALWAYS the one next to it, and not the hypotenuse. The opisit is ALWAYS the one that is, well opposite it. and the hypotenuses is the longest one (opposite the right angle)

lets say the hypotenuse is 5 and B was 3. we have the hypotenuse's value and the opposite's value. This means we must use Sin, as we dont have the adjacent needed for tan or cosin. looking back at how sine looks like (SOH: Sin Opposite/hypotenuse) we know that we have to first work out the opposite divided by the hypotenuse (O&H) which is 0.6. Now we know the equation looks like this: sin 0.6. We are trying to work out the angle, so we have to use sin-1 on a calculator which gives you 36.87 aprox.

to use tan, its the same sort of thing. only (looking back at the formula) which is CAH: Cosin Adjacent/hypotenuse. assuming the adjacent is 4, and the hypotanues is the same (5) its simply cosin-1 (4/5) which is also 36.87. I might explain how to work out the length of side A or B if you have one of the three sides and one of the angle's values

Last edited by yambanshee (2009-03-20 12:33:19)

Offline

 

#48 2009-03-28 06:46:52

Mirror27Studios
Scratcher
Registered: 2009-03-01
Posts: 9

Re: how do I use sin. cos, and tan?

I vaguely get it, this help ossociate the spinning price with the cooridinates of another sprite while it's spinning in air!  This may help me on my Interactive buddy type personage and scroller.  Instead of using a buddy I'm using a robot!  This is also helpful to me because I am in the midsts of making an iPone app and understanding X-code.  I have a sense that trig coordinate tracking is inevitable, so thanx!  XD  Oh yeah, I forgot to mention, I understand and I'm in 7th Grade, part of finding out the answer is basic problem solving while the other half is a bit more high-bel math.  PS:  How do you make those icon/tabs at the end of every message?  smile  Thanks <move(  )steps>Archmage!

Offline

 

#49 2009-03-28 08:28:30

bosox397
Scratcher
Registered: 2008-02-17
Posts: 1000+

Re: how do I use sin. cos, and tan?

Mirror27Studios wrote:

I vaguely get it, this help ossociate the spinning price with the cooridinates of another sprite while it's spinning in air!  This may help me on my Interactive buddy type personage and scroller.  Instead of using a buddy I'm using a robot!  This is also helpful to me because I am in the midsts of making an iPone app and understanding X-code.  I have a sense that trig coordinate tracking is inevitable, so thanx!  XD  Oh yeah, I forgot to mention, I understand and I'm in 7th Grade, part of finding out the answer is basic problem solving while the other half is a bit more high-bel math.  PS:  How do you make those icon/tabs at the end of every message?  smile  Thanks <move(  )steps>Archmage!

Those icon tabs are called signatures. You can have one after you get 50 posts.


Dear Scratch Users,
I'm done with scratch, or at least making projects. I have made one last big game, thats both fun and teaches a lesson about water. It'd mean a lot if you gave me feedback.                              http://scratch.mit.edu/projects/bosox397/569201

Offline

 

#50 2009-04-03 13:15:32

BoltBait
Scratcher
Registered: 2009-03-09
Posts: 1000+

Re: how do I use sin. cos, and tan?

Here is a script I wrote to help another Scratcher:

It uses ATAN to keep Sprite1 pointing away from Sprite2:
http://i57.photobucket.com/albums/g228/BoltBait/PointAway.gif

Full sized view: http://i57.photobucket.com/albums/g228/BoltBait/PointAway.gif

Basically, it uses ATAN to convert Cartesian coordinates of Sprite2 (x,y) into polar coordinates (r, th).  Then, the angle theta (th) is used to calculate the opposite angle.

This is the type of math you learn in Algebra II class.


Animated sigs must be banned!
http://boltbait.com/j.pnghttp://boltbait.com/s.pnghttp://boltbait.com/d.pnghttp://boltbait.com/a.pnghttp://boltbait.com/p.png

Offline

 
  • Index
  •  » FAQ
  •  » how do I use sin. cos, and tan?

Board footer