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

#1 2011-12-03 06:03:21

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Help with Trigonometry

I have the variables "total speed", "x velocity", and "y velocity".
I want to convert the total speed into x velocity and y velocity based on the direction. So if the total speed is 5 and the direction is 45, the x velocity and y velocity would be 2.5. Is there a way of doing this with Trigonometry?

Offline

 

#2 2011-12-03 06:36:32

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Help with Trigonometry

Indeed there is!
You can try looking at my trig test here for a working example!

In general however, these are the scripts:

X vel = 0 - sin(direction) * speed
Y vel = 0 - cos(direction) * speed

Offline

 

#3 2011-12-03 07:17:28

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Help with Trigonometry

LS97 wrote:

Indeed there is!
You can try looking at my trig test here for a working example!

In general however, these are the scripts:

X vel = 0 - sin(direction) * speed
Y vel = 0 - cos(direction) * speed

Thanks! That helped a lot. Although I didn't need the "0 -" because It needed to be always be positive but that's not too hard.  smile

Offline

 

#4 2012-02-23 08:25:03

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Help with Trigonometry

LS97 wrote:

Indeed there is!
You can try looking at my trig test here for a working example!

In general however, these are the scripts:

X vel = 0 - sin(direction) * speed
Y vel = 0 - cos(direction) * speed

I've just come back after a while and tried it again on a different project, there was a bug where the y velocity was either -1.0 or 1.0 when the angle was 0. Why is this? And how do I fix it?

Offline

 

#5 2012-02-23 08:43:57

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Help with Trigonometry

Splodgey wrote:

LS97 wrote:

Indeed there is!
You can try looking at my trig test here for a working example!

In general however, these are the scripts:

X vel = 0 - sin(direction) * speed
Y vel = 0 - cos(direction) * speed

I've just come back after a while and tried it again on a different project, there was a bug where the y velocity was either -1.0 or 1.0 when the angle was 0. Why is this? And how do I fix it?

Oh I just looked at the trig test. It is:

set [x vel v] to ((speed) * ([sin v] of (direction)))
set [y vel v] to ((speed) * ([cos v] of (direction)))

Last edited by Splodgey (2012-02-23 09:05:30)

Offline

 

#6 2012-02-23 08:49:49

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: Help with Trigonometry

Splodgey wrote:

Splodgey wrote:

LS97 wrote:

Indeed there is!
You can try looking at my trig test here for a working example!

In general however, these are the scripts:

X vel = 0 - sin(direction) * speed
Y vel = 0 - cos(direction) * speed

I've just come back after a while and tried it again on a different project, there was a bug where the y velocity was either -1.0 or 1.0 when the angle was 0. Why is this? And how do I fix it?

Oh I just looked at the trig test. It is:

set [x vel v] to ((speed) * ([sin v] of (direction))) //Not sure why they are variables...
set [y vel v] to ((speed) * ([cos v] of (direction)))

I fixed it for you.

Offline

 

#7 2012-02-23 09:04:10

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Help with Trigonometry

rdococ wrote:

Splodgey wrote:

Splodgey wrote:


I've just come back after a while and tried it again on a different project, there was a bug where the y velocity was either -1.0 or 1.0 when the angle was 0. Why is this? And how do I fix it?

Oh I just looked at the trig test. It is:

set [x vel v] to ((speed) * ([sin v] of (direction))) //Not sure why they are variables...
set [y vel v] to ((speed) * ([cos v] of (direction)))

I fixed it for you.

thanks, I'll edit that. That means there's a bug in Paddle2see's Scratch block generator.  tongue

Offline

 

#8 2012-02-23 10:49:53

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Help with Trigonometry

Splodgey wrote:

rdococ wrote:

Splodgey wrote:


Oh I just looked at the trig test. It is:

set [x vel v] to ((speed) * ([sin v] of (direction))) //Not sure why they are variables...
set [y vel v] to ((speed) * ([cos v] of (direction)))

I fixed it for you.

thanks, I'll edit that. That means there's a bug in Paddle2see's Scratch block generator.  tongue

It's actually by JSO.  wink


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#9 2012-02-23 13:46:33

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Help with Trigonometry

Hardmath123 wrote:

Splodgey wrote:

rdococ wrote:

I fixed it for you.

thanks, I'll edit that. That means there's a bug in Paddle2see's Scratch block generator.  tongue

It's actually by JSO.  wink

The block generator...?  hmm

Better not get off topic...

Last edited by Splodgey (2012-02-23 13:47:27)

Offline

 

#10 2012-02-23 14:12:23

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: Help with Trigonometry

Splodgey wrote:

Hardmath123 wrote:

Splodgey wrote:


thanks, I'll edit that. That means there's a bug in Paddle2see's Scratch block generator.  tongue

It's actually by JSO.  wink

The block generator...?  hmm

Better not get off topic...

yes its by JSO for the forums
[/offtopic]


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#11 2012-02-25 03:31:17

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Help with Trigonometry

fanofcena wrote:

Splodgey wrote:

Hardmath123 wrote:

It's actually by JSO.  wink

The block generator...?  hmm

Better not get off topic...

yes its by JSO for the forums
[/offtopic]

No, no, no not the scratchblocks, the block generator project!

Offline

 

#12 2012-02-25 10:17:12

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: Help with Trigonometry

Splodgey wrote:

fanofcena wrote:

Splodgey wrote:


The block generator...?  hmm

Better not get off topic...

yes its by JSO for the forums
[/offtopic]

No, no, no not the scratchblocks, the block generator project!

oh yes that one is by Paddle2see

[/offtopic permanent]


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

Board footer