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.
- NoxSpooth
- Scratcher
1000+ posts
'Distance to x:(), y:()' block
Totally! true, scratch could use a ^ block…
Exponentials are awesome
- 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?
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…
- Failord
- Scratcher
1000+ posts
'Distance to x:(), y:()' block
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.
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.
- lakshay
- Scratcher
26 posts
'Distance to x:(), y:()' block
I forgot about it. Thanks! Easier:
distance=sqrt((x position - sprite's x position)² + (y position - sprite's y position)²)
Pythagoras…
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)))
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
I have one in my “custom blocks” project. 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)))
Remember that scratch angles go clockwise and start at 12 o'clock, while in trig we go ccw starting at 3 o'clock.
- lakshay
- Scratcher
26 posts
'Distance to x:(), y:()' block
I have one in my “custom blocks” project. 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)))
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
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). 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 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
We've established that a long time ago… 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.