Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Distance from (x) (y) (z)?
- COOL_GAMES_2015
-
18 posts
Distance from (x) (y) (z)?
Hello! I have a short question: Does anyone have an idea how to make a „distance from (x) (y) (z)“ Block?
- deck26
-
1000+ posts
Distance from (x) (y) (z)?
Use Pythagoras. sqrt (x^2 + y^2 + z^2) should give you what you need.
If you think about the xy plane you can get the square of the distance on that plane by adding the squares of x and y. You then just have another 2D right angle triangle so you can add that square to z-sqaured and take the square root as normal.
If you think about the xy plane you can get the square of the distance on that plane by adding the squares of x and y. You then just have another 2D right angle triangle so you can add that square to z-sqaured and take the square root as normal.
- COOL_GAMES_2015
-
18 posts
Distance from (x) (y) (z)?
Use Pythagoras. sqrt (x^2 + y^2 + z^2) should give you what you need.
If you think about the xy plane you can get the square of the distance on that plane by adding the squares of x and y. You then just have another 2D right angle triangle so you can add that square to z-sqaured and take the square root as normal.
I don`t really understand xD Could you pls put te code in here and give me the link to the right code? That would be so great

- Nezon
-
1000+ posts
Distance from (x) (y) (z)?
They're born in 2014 so they most likely don't. Do you understand Pythagoras Theorem?
Last edited by Nezon (Oct. 30, 2021 21:54:10)
- deck26
-
1000+ posts
Distance from (x) (y) (z)?
They're born in 2014 so they most likely don't. Do you understand Pythagoras Theorem?
So working with 3D coordinates may also be a bit advanced!
Anyway, to elaborate on my original post. You have two xyz coordinate positions. You need to calculate the differences between the x values, the difference between y values and the difference between the z values - let's call the differences xd, yd and zd. Then the distance between the two points is
([sqrt v] of ( (((xd) * (xd)) + ((yd) * (yd))) + ((zd) * (zd)))
Last edited by deck26 (Oct. 31, 2021 10:34:16)
- PhilHub
-
69 posts
Distance from (x) (y) (z)?
They're born in 2014 so they most likely don't. Do you understand Pythagoras Theorem?
So working with 3D coordinates may also be a bit advanced!
Anyway, to elaborate on my original post. You have two xyz coordinate positions. You need to calculate the differences between the x values, the difference between y values and the difference between the z values - let's call the differences xd, yd and zd. Then the distance between the two points is([sqrt v] of ( (((xd) * (xd)) + ((yd) * (yd))) + ((zd) * (zd)))
He’s right but actually it’s a*a+b*b=c*c
([sqrt v] of (((a) * (a)) + ((b) * (b))))
- deck26
-
1000+ posts
Distance from (x) (y) (z)?
You're ignoring the fact that the question involves a 3 dimensional space.They're born in 2014 so they most likely don't. Do you understand Pythagoras Theorem?
So working with 3D coordinates may also be a bit advanced!
Anyway, to elaborate on my original post. You have two xyz coordinate positions. You need to calculate the differences between the x values, the difference between y values and the difference between the z values - let's call the differences xd, yd and zd. Then the distance between the two points is([sqrt v] of ( (((xd) * (xd)) + ((yd) * (yd))) + ((zd) * (zd)))
He’s right but actually it’s a*a+b*b=c*c([sqrt v] of (((a) * (a)) + ((b) * (b))))
- cIoudyness
-
500+ posts
Distance from (x) (y) (z)?
You're ignoring the fact that the question involves a 3 dimensional space.They're born in 2014 so they most likely don't. Do you understand Pythagoras Theorem?
So working with 3D coordinates may also be a bit advanced!
Anyway, to elaborate on my original post. You have two xyz coordinate positions. You need to calculate the differences between the x values, the difference between y values and the difference between the z values - let's call the differences xd, yd and zd. Then the distance between the two points is([sqrt v] of ( (((xd) * (xd)) + ((yd) * (yd))) + ((zd) * (zd)))
He’s right but actually it’s a*a+b*b=c*c([sqrt v] of (((a) * (a)) + ((b) * (b))))
(me not understanding pythagorean theorem in multiple dimensions, sorry for wasting your time)
Last edited by cIoudyness (Oct. 31, 2021 18:43:11)
- helloworldbyeworld
-
1000+ posts
Distance from (x) (y) (z)?
No, because you’re still squaring the terms, so you only need to square root it. Having 3 terms (x, y, z) doesn’t mean that you need to cube and cube root them. If you have 100 dimensions and 100 terms, you will still only need to square and square root, not ^100 and 100-root.You're ignoring the fact that the question involves a 3 dimensional space.(snip)They're born in 2014 so they most likely don't.
So working with 3D coordinates may also be a bit advanced!
Anyway, to elaborate on my original post. You have two xyz coordinate positions. You need to calculate the differences between the x values, the difference between y values and the difference between the z values - let's call the differences xd, yd and zd. Then the distance between the two points is([sqrt v] of ( (((xd) * (xd)) + ((yd) * (yd))) + ((zd) * (zd)))
He’s right but actually it’s a*a+b*b=c*c([sqrt v] of (((a) * (a)) + ((b) * (b))))
hold on, but with three dimensions (x, y and z) should it be a cube root instead? and if so how to code that?
- cIoudyness
-
500+ posts
Distance from (x) (y) (z)?
ah.No, because you’re still squaring the terms, so you only need to square root it. Having 3 terms (x, y, z) doesn’t mean that you need to cube and cube root them. If you have 100 dimensions and 100 terms, you will still only need to square and square root, not ^100 and 100-root.You're ignoring the fact that the question involves a 3 dimensional space.(snip)They're born in 2014 so they most likely don't.
So working with 3D coordinates may also be a bit advanced!
Anyway, to elaborate on my original post. You have two xyz coordinate positions. You need to calculate the differences between the x values, the difference between y values and the difference between the z values - let's call the differences xd, yd and zd. Then the distance between the two points is([sqrt v] of ( (((xd) * (xd)) + ((yd) * (yd))) + ((zd) * (zd)))
He’s right but actually it’s a*a+b*b=c*c([sqrt v] of (((a) * (a)) + ((b) * (b))))
hold on, but with three dimensions (x, y and z) should it be a cube root instead? and if so how to code that?
how would you code finding a cube root? there's probably some really obvious answer to this that i can't imagine
- deck26
-
1000+ posts
Distance from (x) (y) (z)?
how would you code finding a cube root? there's probably some really obvious answer to this that i can't imagine
Use logs. Take the log, divide by 3 and raise the base to the power of that value.
- helloworldbyeworld
-
1000+ posts
Distance from (x) (y) (z)?
There’s no simple series of blocks that you can use to find a cube root. Instead, try using an algorithm like Newton’s method. Also, why do you need to calculate the cube root of a number when I just said that you need to square root the result, not cube root it?ah.No, because you’re still squaring the terms, so you only need to square root it. Having 3 terms (x, y, z) doesn’t mean that you need to cube and cube root them. If you have 100 dimensions and 100 terms, you will still only need to square and square root, not ^100 and 100-root.You're ignoring the fact that the question involves a 3 dimensional space.(snip)(snip)
So working with 3D coordinates may also be a bit advanced!
Anyway, to elaborate on my original post. You have two xyz coordinate positions. You need to calculate the differences between the x values, the difference between y values and the difference between the z values - let's call the differences xd, yd and zd. Then the distance between the two points is([sqrt v] of ( (((xd) * (xd)) + ((yd) * (yd))) + ((zd) * (zd)))
He’s right but actually it’s a*a+b*b=c*c([sqrt v] of (((a) * (a)) + ((b) * (b))))
hold on, but with three dimensions (x, y and z) should it be a cube root instead? and if so how to code that?
how would you code finding a cube root? there's probably some really obvious answer to this that i can't imagine
Edit: Why don’t you just use the logarithm method, as @deck26 mentioned?
Last edited by helloworldbyeworld (Oct. 31, 2021 18:55:51)
- The_Imaginarium
-
1000+ posts
Distance from (x) (y) (z)?
Use logarithmic properties how would you code finding a cube root? there's probably some really obvious answer to this that i can't imagine
([10 ^ v] of (([log v] of (x)) * ((1) / (3))))
This works because log(a) * b equals log(a^b), and the log is eliminated by the base to leave a^b.
And take note that a^(1/3) is cube root
- cIoudyness
-
500+ posts
Distance from (x) (y) (z)?
because curiosity (also thanks)
Last edited by cIoudyness (Oct. 31, 2021 19:15:16)
- COOL_GAMES_2015
-
18 posts
Distance from (x) (y) (z)?
No I’m 7 years old xD Do you understand Pythagoras Theorem?
- COOL_GAMES_2015
-
18 posts
Distance from (x) (y) (z)?
They're born in 2014 so they most likely don't. Do you understand Pythagoras Theorem?
So working with 3D coordinates may also be a bit advanced!
Anyway, to elaborate on my original post. You have two xyz coordinate positions. You need to calculate the differences between the x values, the difference between y values and the difference between the z values - let's call the differences xd, yd and zd. Then the distance between the two points is([sqrt v] of ( (((xd) * (xd)) + ((yd) * (yd))) + ((zd) * (zd)))
And how would It look like if you use the Variable names of this: https://turbowarp.org/592493267
- deck26
-
1000+ posts
Distance from (x) (y) (z)?
Exactly as I said - you need to calculate the x difference, the y difference and the z difference. Using xd, yd and zd to store those gives you what you need. That's neater, in my opinion, than having to work out each difference each time you need it which would give you something likeThey're born in 2014 so they most likely don't. Do you understand Pythagoras Theorem?
So working with 3D coordinates may also be a bit advanced!
Anyway, to elaborate on my original post. You have two xyz coordinate positions. You need to calculate the differences between the x values, the difference between y values and the difference between the z values - let's call the differences xd, yd and zd. Then the distance between the two points is([sqrt v] of ( (((xd) * (xd)) + ((yd) * (yd))) + ((zd) * (zd)))
And how would It look like if you use the Variable names of this: https://turbowarp.org/592493267
([sqrt v] of ( ((((x1) - (x2)) * ((x1) - (x2))) + (((y1) - (y2)) * ((y1) - (y2)))) + (((z1) - (z2)) * ((z1) - (z2))))
- scratchering_coder
-
500+ posts
Distance from (x) (y) (z)?
It's complex for you, if you're a kid, when you will grow up you will learn it in school and understand it. i don't understand them either so don't worry.
- COOL_GAMES_2015
-
18 posts
Distance from (x) (y) (z)?
Exactly as I said - you need to calculate the x difference, the y difference and the z difference. Using xd, yd and zd to store those gives you what you need. That's neater, in my opinion, than having to work out each difference each time you need it which would give you something likeThey're born in 2014 so they most likely don't. Do you understand Pythagoras Theorem?
So working with 3D coordinates may also be a bit advanced!
Anyway, to elaborate on my original post. You have two xyz coordinate positions. You need to calculate the differences between the x values, the difference between y values and the difference between the z values - let's call the differences xd, yd and zd. Then the distance between the two points is([sqrt v] of ( (((xd) * (xd)) + ((yd) * (yd))) + ((zd) * (zd)))
And how would It look like if you use the Variable names of this: https://turbowarp.org/592493267([sqrt v] of ( ((((x1) - (x2)) * ((x1) - (x2))) + (((y1) - (y2)) * ((y1) - (y2)))) + (((z1) - (z2)) * ((z1) - (z2))))
Yeah that’s great Tysm that’s what I need

- Discussion Forums
- » Help with Scripts
-
» Distance from (x) (y) (z)?