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

#1 2010-05-05 02:53:14

Common_Sense
Scratcher
Registered: 2009-12-21
Posts: 100+

Math problem with simple script

Say direction is 0 and length is 10, it ld_x should be 10 and ld_y should be 0.
It works in this case.
http://img195.imageshack.us/img195/7681/scripts.gif

If I make dir start out as 45, ld_x is still 10 and ld_y is 0.1

This should work, though.

Here's a diagram of what I mean.

Can anyone tell me what I'm doing wrong?

http://img215.imageshack.us/img215/3250/diagramm.gif


http://i44.tinypic.com/6dvort.png

Offline

 

#2 2010-05-05 08:27:47

Ratty1967UK
Scratcher
Registered: 2007-05-16
Posts: 88

Re: Math problem with simple script

Not quite sure I fully understand where you're going with this, but I doubt you need PI in your trigonometric functions - just give them the angle and you get the sine or cosine of that angle back

Last edited by Ratty1967UK (2010-05-05 08:28:34)

Offline

 

#3 2010-05-05 08:35:48

Phi_Lho
Scratcher
Registered: 2010-03-22
Posts: 75

Re: Math problem with simple script

Yes, no need to convert angles from degrees to radians, trigonometric functions in Scratch work already in degrees.


http://i241.photobucket.com/albums/ff159/PhiLho/KM150.pnghttp://i241.photobucket.com/albums/ff159/PhiLho/PhiLhoLogo.png

Offline

 

#4 2010-05-05 15:47:10

Common_Sense
Scratcher
Registered: 2009-12-21
Posts: 100+

Re: Math problem with simple script

I don't think you understand what I mean.

I'm trying to figure out what the X and Y of L pixels to the right, and D pixels rotated based on it's center.

Is there an easier way of doing this?


http://i44.tinypic.com/6dvort.png

Offline

 

#5 2010-05-05 18:14:01

Ratty1967UK
Scratcher
Registered: 2007-05-16
Posts: 88

Re: Math problem with simple script

so on your little picture above, you want to know the (x,y) position of the point at the end of the light blue line near the word "rotates"?

Offline

 

#6 2010-05-05 18:59:12

Common_Sense
Scratcher
Registered: 2009-12-21
Posts: 100+

Re: Math problem with simple script

Ratty1967UK wrote:

so on your little picture above, you want to know the (x,y) position of the point at the end of the light blue line near the word "rotates"?

For the third time now, yes...


http://i44.tinypic.com/6dvort.png

Offline

 

#7 2010-05-06 09:52:53

Ratty1967UK
Scratcher
Registered: 2007-05-16
Posts: 88

Re: Math problem with simple script

calm down kid! lol

assume px and py are the co-ordinates of the player...

x = l * sin(dir) + px
y = l * cos(dir) + py

all angles should be in degrees - no pi's required

are you ok turning that into scratch blocks?

Offline

 

#8 2010-05-06 10:45:08

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

Re: Math problem with simple script

Scratch uses degrees, not radians.
I had the problem using actionscript for the first time, but the other way round.


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

 

Board footer