Discuss Scratch

COOL_GAMES_2015
Scratcher
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
Scratcher
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.
COOL_GAMES_2015
Scratcher
18 posts

Distance from (x) (y) (z)?

deck26 wrote:

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 I`d give credit! https://turbowarp.org/592493267
deck26
Scratcher
1000+ posts

Distance from (x) (y) (z)?

Do you understand Pythagoras Theorem?
Nezon
Scratcher
1000+ posts

Distance from (x) (y) (z)?

deck26 wrote:

Do you understand Pythagoras Theorem?
They're born in 2014 so they most likely don't.

Last edited by Nezon (Oct. 30, 2021 21:54:10)

deck26
Scratcher
1000+ posts

Distance from (x) (y) (z)?

Nezon wrote:

deck26 wrote:

Do you understand Pythagoras Theorem?
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)))

Last edited by deck26 (Oct. 31, 2021 10:34:16)

PhilHub
Scratcher
69 posts

Distance from (x) (y) (z)?

deck26 wrote:

Nezon wrote:

deck26 wrote:

Do you understand Pythagoras Theorem?
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))))
deck26
Scratcher
1000+ posts

Distance from (x) (y) (z)?

PhilHub wrote:

deck26 wrote:

Nezon wrote:

deck26 wrote:

Do you understand Pythagoras Theorem?
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))))
You're ignoring the fact that the question involves a 3 dimensional space.
cIoudyness
Scratcher
500+ posts

Distance from (x) (y) (z)?

deck26 wrote:

PhilHub wrote:

deck26 wrote:

Nezon wrote:

deck26 wrote:

Do you understand Pythagoras Theorem?
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))))
You're ignoring the fact that the question involves a 3 dimensional space.

(me not understanding pythagorean theorem in multiple dimensions, sorry for wasting your time)

Last edited by cIoudyness (Oct. 31, 2021 18:43:11)

helloworldbyeworld
Scratcher
1000+ posts

Distance from (x) (y) (z)?

cIoudyness wrote:

deck26 wrote:

PhilHub wrote:

deck26 wrote:

Nezon wrote:

deck26 wrote:

(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))))
You're ignoring the fact that the question involves a 3 dimensional space.

hold on, but with three dimensions (x, y and z) should it be a cube root instead? and if so how to code that?
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.
cIoudyness
Scratcher
500+ posts

Distance from (x) (y) (z)?

helloworldbyeworld wrote:

cIoudyness wrote:

deck26 wrote:

PhilHub wrote:

deck26 wrote:

Nezon wrote:

deck26 wrote:

(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))))
You're ignoring the fact that the question involves a 3 dimensional space.

hold on, but with three dimensions (x, y and z) should it be a cube root instead? and if so how to code that?
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.
ah.

how would you code finding a cube root? there's probably some really obvious answer to this that i can't imagine
deck26
Scratcher
1000+ posts

Distance from (x) (y) (z)?

cIoudyness wrote:

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
Scratcher
1000+ posts

Distance from (x) (y) (z)?

cIoudyness wrote:

helloworldbyeworld wrote:

cIoudyness wrote:

deck26 wrote:

PhilHub wrote:

deck26 wrote:

Nezon wrote:

deck26 wrote:

(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))))
You're ignoring the fact that the question involves a 3 dimensional space.

hold on, but with three dimensions (x, y and z) should it be a cube root instead? and if so how to code that?
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.
ah.

how would you code finding a cube root? there's probably some really obvious answer to this that i can't imagine
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?

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
Scratcher
1000+ posts

Distance from (x) (y) (z)?

cIoudyness wrote:

how would you code finding a cube root? there's probably some really obvious answer to this that i can't imagine
Use logarithmic properties

([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
Scratcher
500+ posts

Distance from (x) (y) (z)?

because curiosity (also thanks)

Last edited by cIoudyness (Oct. 31, 2021 19:15:16)

COOL_GAMES_2015
Scratcher
18 posts

Distance from (x) (y) (z)?

deck26 wrote:

Do you understand Pythagoras Theorem?
No I’m 7 years old xD
COOL_GAMES_2015
Scratcher
18 posts

Distance from (x) (y) (z)?

deck26 wrote:

Nezon wrote:

deck26 wrote:

Do you understand Pythagoras Theorem?
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)))

And how would It look like if you use the Variable names of this: https://turbowarp.org/592493267
deck26
Scratcher
1000+ posts

Distance from (x) (y) (z)?

COOL_GAMES_2015 wrote:

deck26 wrote:

Nezon wrote:

deck26 wrote:

Do you understand Pythagoras Theorem?
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)))

And how would It look like if you use the Variable names of this: https://turbowarp.org/592493267
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 like

([sqrt v] of ( ((((x1) - (x2)) * ((x1) - (x2))) + (((y1) - (y2)) * ((y1) - (y2)))) + (((z1) - (z2)) * ((z1) - (z2))))
scratchering_coder
Scratcher
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
Scratcher
18 posts

Distance from (x) (y) (z)?

deck26 wrote:

COOL_GAMES_2015 wrote:

deck26 wrote:

Nezon wrote:

deck26 wrote:

Do you understand Pythagoras Theorem?
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)))

And how would It look like if you use the Variable names of this: https://turbowarp.org/592493267
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 like

([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 I’ll giv you credit.

Powered by DjangoBB