Discuss Scratch

lakshay
Scratcher
26 posts

'Distance to x:(), y:()' block

Presently, we can't find the distance of a sprite from a point. So, I would like to suggest a “Distance to x: (), y: ()” block. Please make this new block because I have started a project where this will be needed.

Last edited by lakshay (May 17, 2013 13:57:18)


I want to die while sleeping peacefully like my grandfather, not screaming in terror like his passengers.
xlk
Scratcher
100+ posts

'Distance to x:(), y:()' block

Easier:
distance=sqrt((x position - sprite's x position)² + (y position - sprite's y position)²)
Pythagoras…

Scratch12300
Scratcher
500+ posts

'Distance to x:(), y:()' block

xlk wrote:

Easier:
distance=sqrt((x position - sprite's x position)² + (y position - sprite's y position)²)
Pythagoras…
There is no ^ block.

Scratch12300
Scratcher
500+ posts

'Distance to x:(), y:()' block

xlk wrote:

Easier:
distance=sqrt((x position - sprite's x position)² + (y position - sprite's y position)²)
Pythagoras…
There is no ^ block.

kayybee
Scratcher
1000+ posts

'Distance to x:(), y:()' block

x^2=x*x
xlk
Scratcher
100+ posts

'Distance to x:(), y:()' block

true, scratch could use a ^ block…
Exponentials are awesome

NoxSpooth
Scratcher
1000+ posts

'Distance to x:(), y:()' block

xlk wrote:

true, scratch could use a ^ block…
Exponentials are awesome
Totally!
Failord
Scratcher
1000+ posts

'Distance to x:(), y:()' block

You could take the long way and multiply it by itself, because that's what ^2 does, anyway.

Like this: distance=sqrt(((x position - sprite's x position)*(x position - sprite's x position) + ((y position - sprite's y position) * (y position - sprite's y position)))

We could use an exponent block, still, because this way is INCREDIBLY inflexible, as well as so long and annoying to put together. Without the exponent, you can't have ((Whatever #)^(Variable!)) , if that made any sense at all.

But the easiest way is just to make a sprite to go to that point, and have the sprite you want to point at that point point at your point sprite. Pointedly. Do you see my point?

Thanks for the ride, Scratch Team and community! Unfortunately, the time has come for me to move on from Scratch, so I'll no longer be using the forums. Thanks again, and farewell!
Invisible text! This will show you if a profile I claim to be mine IS mine. Just remember to visit the profile and see if I confirmed in the comments.
For old time's sake, see the revolutionary Laser Battle 2.0! Also see Unstoppable Game!

And no, the evil kumquats didn't alter my signature…
xlk
Scratcher
100+ posts

'Distance to x:(), y:()' block

just noticed that it will be possible to make cubic roots with “^” blocks….
Even more awesome

Failord
Scratcher
1000+ posts

'Distance to x:(), y:()' block

xlk wrote:

just noticed that it will be possible to make cubic roots with “^” blocks….
Even more awesome

OOOOOOHHHHHH YEAAAAAAAHHHHH!!!

Although I think the reason they aren't adding it is because if the numbers get too big, it might crash the system. But that could potentially happen in the current Scratch anyway, so who cares?

Last edited by Failord (May 18, 2013 00:49:49)


Thanks for the ride, Scratch Team and community! Unfortunately, the time has come for me to move on from Scratch, so I'll no longer be using the forums. Thanks again, and farewell!
Invisible text! This will show you if a profile I claim to be mine IS mine. Just remember to visit the profile and see if I confirmed in the comments.
For old time's sake, see the revolutionary Laser Battle 2.0! Also see Unstoppable Game!

And no, the evil kumquats didn't alter my signature…
kayybee
Scratcher
1000+ posts

'Distance to x:(), y:()' block

For now you can use logarithms to manipulate exponents.
x^y=e^(y*ln(x))
or
x^y=10^(y*log(x))
e^, 10^, log, and ln are all available in that last one in operators that includes like all of the advanced math operators.
xlk
Scratcher
100+ posts

'Distance to x:(), y:()' block

thankyou kayybee, I never thought of that round about…

lakshay
Scratcher
26 posts

'Distance to x:(), y:()' block

xlk wrote:

Easier:
distance=sqrt((x position - sprite's x position)² + (y position - sprite's y position)²)
Pythagoras…
I forgot about it. Thanks!

I want to die while sleeping peacefully like my grandfather, not screaming in terror like his passengers.
lakshay
Scratcher
26 posts

'Distance to x:(), y:()' block

Now I realised that I would also need a “point towards x: () y: ()”. Can I put some code for that?

EDIT: I figured it out. But please feel free to suggest a new method. I have thought about this one (using trigonometry):-
Point in direction(atan of ((abs of (((x position of point)-(x position of sprite))/(abs of((y position of point)-(y position of sprite)))

Last edited by lakshay (June 5, 2013 04:29:18)


I want to die while sleeping peacefully like my grandfather, not screaming in terror like his passengers.
kayybee
Scratcher
1000+ posts

'Distance to x:(), y:()' block

lakshay wrote:

Now I realised that I would also need a “point towards x: () y: ()”. Can I put some code for that?

EDIT: I figured it out. But please feel free to suggest a new method. I have thought about this one (using trigonometry):-
Point in direction( of (( of ((( of point)-( of sprite))/( of(( of point)-( of sprite)))
I have one in my “custom blocks” project.
Remember that scratch angles go clockwise and start at 12 o'clock, while in trig we go ccw starting at 3 o'clock.
turkey3
Scratcher
1000+ posts

'Distance to x:(), y:()' block

Trigonometry can be used to check the distance to an x position, depending on the angle your sprite opens up to it and its relative position to it.

lakshay
Scratcher
26 posts

'Distance to x:(), y:()' block

kayybee wrote:

lakshay wrote:

Now I realised that I would also need a “point towards x: () y: ()”. Can I put some code for that?

EDIT: I figured it out. But please feel free to suggest a new method. I have thought about this one (using trigonometry):-
Point in direction( of (( of ((( of point)-( of sprite))/( of(( of point)-( of sprite)))
I have one in my “custom blocks” project.
Remember that scratch angles go clockwise and start at 12 o'clock, while in trig we go ccw starting at 3 o'clock.

The code is already customised for that.

I want to die while sleeping peacefully like my grandfather, not screaming in terror like his passengers.
lakshay
Scratcher
26 posts

'Distance to x:(), y:()' block

Failord wrote:

But the easiest way is just to make a sprite to go to that point, and have the sprite you want to point at that point point at your point sprite. Pointedly. Do you see my point?
I couldn't do that because there are 100 clones in my project and I am not ready to create 100 sprites (one for each clone).

I want to die while sleeping peacefully like my grandfather, not screaming in terror like his passengers.
turkey3
Scratcher
1000+ posts

'Distance to x:(), y:()' block

distance=sqrt((x position - sprite's x position)(x position - sprite's x position) + (y position - sprite's y position)(y position - sprite's y position))

Since you can't square just multiply the same thing twice as the workaround in the distance formula.

kayybee
Scratcher
1000+ posts

'Distance to x:(), y:()' block

turkey3 wrote:

distance=sqrt((x position - sprite's x position)(x position - sprite's x position) + (y position - sprite's y position)(y position - sprite's y position))

Since you can't square just multiply the same thing twice as the workaround in the distance formula.
We've established that a long time ago…

Powered by DjangoBB