ID:154378
 
What's the formula for determining distance between two points established in three-dimensional space? Euclidean distance, rather than Dantomian.

In fact, if anyone could give me a quick primer on 3 dimensional vectors in general, I'll give you half of the souls I harvest this year.
What's the formula for determining distance between two points established in three-dimensional space? Euclidean distance, rather than Dantomian.

In fact, if anyone could give me a quick primer on 3 dimensional vectors in general, I'll give you half of the souls I harvest this year.

I think the distance formula is:

sqrt((abs(x1 - x2) ** 2) + (abs(y1 - y2) ** 2) + (abs(z1 - z2) ** 2))


This looks like it might be useful for the vectors stuff:

http://www.sparknotes.com/physics/vectors/.dir
LexyBitch wrote:
In fact, if anyone could give me a quick primer on 3 dimensional vectors in general, I'll give you half of the souls I harvest this year.

You really need to work on your incentive package.

flick()
In response to Gughunter
Gughunter wrote:
I think the distance formula is:

sqrt((abs(x1 - x2) ** 2) + (abs(y1 - y2) ** 2) + (abs(z1 - z2) ** 2))

Yes, that's right, but there is no need for the abs() function in there. If the differences come out negative, squaring it still returns a positive.

What other vector questions do you have, Lexy? Adding vectors is easy, you simply add the x components to get the new x, add the y components to get the new y, and add the z components to get the new z. Multiplication is where it get's tricky, but I doubt you'll need it.

Since Guy beat me to the punch, I just request that you let me keep my own soul. :)
In response to Shadowdarke
Shadowdarke wrote:
Gughunter wrote:
I think the distance formula is:

sqrt((abs(x1 - x2) ** 2) + (abs(y1 - y2) ** 2) + (abs(z1 - z2) ** 2))

Yes, that's right, but there is no need for the abs() function in there. If the differences come out negative, squaring it still returns a positive.

What other vector questions do you have, Lexy? Adding vectors is easy, you simply add the x components to get the new x, add the y components to get the new y, and add the z components to get the new z. Multiplication is where it get's tricky, but I doubt you'll need it.

Dang it, folks, stop stealing work!

I'm making a library for vectors, angular calculations, distance formulae, etc. Then again, that's only for two dimensions, so I suppose this doesn't apply. =)

Actually, it's releaseable now, if people want it. I just continually add to it... more of a side-project that I use and adapt while working on my games -- need a feature, I add one to the library in the silent hopes that some day I'll release it. =)


Also... scalar multiplication and dot products are nothing to be afraid of! Yes, I've been taking a pre-calculus course this year, and matter-of-factly I'm actually enjoying it. =)
In response to Spuzzum
Hehe. I like algebra. I guess that's a different thing...

Physics/Geo studies are really fun!
In response to Lord of Water
Physics/Geo studies are really fun!

I like the second. I despise the first. =P
In response to Spuzzum
Spuzzum wrote:
Also... scalar multiplication and dot products are nothing to be afraid of! Yes, I've been taking a pre-calculus course this year, and matter-of-factly I'm actually enjoying it. =)

Dot products aren't too bad, though most people blow a fuse when they see them. Cross products are a bit nastier, but you don't need them until you get into torque and angular momentum.

Calculus is a lot of fun, and quite a different breed of math from the others. Glad to see I'm not the only one to like it. :)
In response to Spuzzum
I agree with ya on that one...I myself don't like physics...but hey as long as you know what your doing, you won't need to worry :)
In response to XCloud
XCloud wrote:
I agree with ya on that one...I myself don't like physics...but hey as long as you know what your doing, you won't need to worry :)

I enjoy the scientific aspect of physical sciences... that is, having a way of relating real life values to numbers and actually coming out with a result that makes sense.

What I don't like, is having to compute those numbers endlessly and solve algebra day-in, day-out. I'm not a big fan of grunt-work math. =P
In response to Shadowdarke
What other questions? Well, multiplication would be nice... I figure multiplying a vector by a scalar is pretty straightforward, right? But I could use a vector by a vector...

Also, if I divide a vector by its magnitude, have I reduced its magnitude to 1? I know I could do the math on that one, but I try to avoid doing math to find out something someone else might know.

And figuring the magnitude of a vector... would I just feed it through my distance proc, with 0,0,0 for the second vector?
In response to LexyBitch
LexyBitch wrote:
What other questions? Well, multiplication would be nice... I figure multiplying a vector by a scalar is pretty straightforward, right? But I could use a vector by a vector...

Yeah, multiplying a vector by a scalar just increases the x and y components appropriately.

The dot product (aka. the scalar product) is what you're looking at when multiplying vectors together. It's pretty hard to explain (a calculus teacher would help immensely =)).

What it results as is

vector_A dot vector_B = Length_of_vector_A * Length_of_vector_B * cos(angle_between_two_vectors)

Note that multiplying two vectors will always yield a scalar quantity (hence the term "scalar product")... that is, you lose the direction.


(One of the most common and useful applications of dot product is to determine differences of angles:

                     vector_A dot vector_B
cos(angle_between) = _____________________

                     length_of_A * length_of_B
)



Also, if I divide a vector by its magnitude, have I reduced its magnitude to 1? I know I could do the math on that one, but I try to avoid doing math to find out something someone else might know.

And figuring the magnitude of a vector... would I just feed it through my distance proc, with 0,0,0 for the second vector?

Dividing a vector by its length (i.e. its magnitude) will result in what is called a "unit vector". Unit vectors are a single unit (i.e. 1) in length, which makes them useful, as you can use them to great effect to find distances of lines on a plane, or even in 3D space, from the origin of the graph.

The magnitude of a vector is equal to

sin A = opp/hyp

if you know the y component and angle. You can determine the magnitude (the hypoteneuse) using the sine and rearranging the terms. You can use the other circular functions (tangent, cosine) to get other results as well based on limited information, but you always need at least two variables to be able to find any other variables.

Note that the dot product is just an expression of the cosine law:

c^2 = a^2 + b^2 - 2AB cos C

(Or whatever the cosine law is. My memory isn't the greatest when it comes to math. =P)
In response to LexyBitch
And figuring the magnitude of a vector... would I just feed it through my distance proc, with 0,0,0 for the second vector?

Yes.
In response to Spuzzum
Spuzzum wrote:
LexyBitch wrote:
What other questions? Well, multiplication would be nice... I figure multiplying a vector by a scalar is pretty straightforward, right? But I could use a vector by a vector...

Yeah, multiplying a vector by a scalar just increases the x and y components appropriately.

The dot product (aka. the scalar product) is what you're looking at when multiplying vectors together. It's pretty hard to explain (a calculus teacher would help immensely =)).

What it results as is

vector_A dot vector_B = Length_of_vector_A * Length_of_vector_B * cos(angle_between_two_vectors)

Note that multiplying two vectors will always yield a scalar quantity (hence the term "scalar product")... that is, you lose the direction.

The quick 'n dirty way I've always been taught is to take the product of the X components times the product of the two Y components; i.e.,

<X1, Y1> dot <X2, Y2> = X1 * X2 + Y1 * Y2

I'm not sure how this would work in three-dimensional space, but a logical guess would be to simply add up the products of all three components.
In response to Spuzzum
Spuzzum wrote:
The dot product (aka. the scalar product) is what you're looking at when multiplying vectors together. It's pretty hard to explain (a calculus teacher would help immensely =)).

What it results as is

vector_A dot vector_B = Length_of_vector_A * Length_of_vector_B * cos(angle_between_two_vectors)

I think this can be simplified to
A·B = Ax*Bx + Ay*By + Az*Bz
I'll have to dig out my Physics book when I get home to verify.

Note that multiplying two vectors will always yield a scalar quantity (hence the term "scalar product")... that is, you lose the direction.

This is only true of dot products. The cross product yeilds a vector that is perpendicular to the plane defined by the two vectors being multiplied. To confuse things more, cross products are non-communative: A x B = -B x A

I can't even guess the formulas for cross products, since I used them so rarely. I'll have to look them up.

And figuring the magnitude of a vector... would I just feed it through my distance proc, with 0,0,0 for the second vector?

In addition to the info Spuzzum provided, yes the magnitude of a vector can be calculated by the distance formula. One point is the tip of the vector and the other point is the tail, which is usually (0,0,0)

Out of curiousity, why in blazes are you interested in vector multiplication?
In response to Shadowdarke
I can't even guess the formulas for cross products, since I used them so rarely. I'll have to look them up.

I don't know how you'd figure them for three-dimensional space, but if I remember correctly the two-dimensional form is pretty similar to the annoying cosine dot product formula... I think it's the two vectors' magnitudes multiplied, times the sine of the angle between them (that's just the dot product, using sine instead of cosine... I think) time a unit vector perpendicular to both of the original vectors (this would be along the z-axis if you were to rotate the two vectors so that they lie in the x-y plane). Actually, come to think of it I don't think you'd need to change anything to use this formula for three-dimensional vectors.
LexyBitch wrote:
What's the formula for determining distance between two points established in three-dimensional space? Euclidean distance, rather than Dantomian.

In fact, if anyone could give me a quick primer on 3 dimensional vectors in general, I'll give you half of the souls I harvest this year.

Distance between two points is the same in 3 dimensions as 2, except you add another term to the distance formula:
// dx, dy, and dz are (x1-x2), (y1-y2), (z1-z2)
d2=sqrt(dx**2+dy**2) // 2 dimensions
d3=sqrt(dx**2+dy**2+dz**2) // 3 dimensions

(This can be derived by pretending the 2-dimensional d2 and dz make up another right triangle, and so d3=sqrt(d2**2+z**2)=sqrt(dx**2+dy**2+dz**2). It works out the same. For any N-dimensional vector, just add as many terms as you have dimensions.)

The magnitude of a vector uses the same formula:
mag(v)=sqrt(vx**2+vy**2+vz**2)

Multiplying by a scalar is as simple as you thought:

v*s=<vx*s,vy*s,vz*s>

Multiplying a vector by a vector isn't possible, because the operation just doesn't exist. However, there are dot products and cross products to consider.

The dot product is the sum of the products of the components of two vectors: I.e., x1*x2+y1*y2+.... This works the same way as the magnitude formula (without the square root), where more dimensions means more terms. Magnitude can also be expressed as mag(v)=sqrt(dot(v,v)) (or v.v as the notation normally goes).
dot(u,v)=ux*vx+uy*vy+uz*vz

The dot product is equal to mag(u)*mag(v)*cos(UV), where UV is the angle between them. This means that if the dot product equals 0, the two vectors are orthogonal (at a right angle); at >0, they point in the same general direction; <0, away from each other.

A cross product is somewhat different. Given two vectors, u and v, it will give you a vector that's orthogonal to both of them. mag(cross(u,v))=mag(u)*mag(v)*abs(sin(UV)); this means that if u and v are multiples of each other, the result is <0,0,0>. The cross product is usually calculated with matrices, but here's the formula all spelled out:

cross(u,v)=<uy*vz-uz*vy,uz*vx-ux*vz,ux*vy-uy*vx>

As you can see, the order of u and v does matter. cross(<1,0,0>,<0,1,0>)=<0,0,1>, but cross(<0,1,0>,<1,0,0>)=<0,0,-1>.
In two dimensions, there is no cross product; but you can find an orthogonal vector with <-y,x>. In N dimensions, you'd use N-1 vectors, using a matrix determinant to find the cross product. (I doubt you'll have any use for a 4-dimensional cross product, though.)

Other formulas you may find useful:

Distance of a point Q to a plane (normal vector N, centered at P):

(Q-P).N/mag(N) (distance may be negative, indicating Q is "behind" the plane)

Portion of vector u in direction of v (called "projection of u onto v", like u is a sundial and the projection is its shadow on v, the "ground"):

proj(u,v)=v*(u.v/v.v) (u.v and v.v are scalar)

Closest distance from point P to (infinite) line AB:

dist(P,A+proj(P,B-A))

I hope all that helps.

Lummox JR
In response to Shadowdarke
Out of curiousity, why in blazes are you interested in vector multiplication?

Call it a feasibility study for a very distant future project.

Picture a starship-based MUD. Ships and stations are represented as typical room arrangements, but with directions of up, down, port, starboard, fore, and aft. Each 'starship' object is also given a position and orientation in 3D space.

Now, I fire a particle beam through your ship... if we can figure out the point of impact on the "surface", which rooms will it end up passing through on its way to the other side? I'd need to compare the angle of the ship to the angle of the beam... am I wrong in thinking this would be a good place to use products?
In response to Spuzzum
I can totally say...I feel your pain...lol. I have to do endless algebra questions coming outta my kazoo. I only do em cause its part of my school credit :(
In response to XCloud
XCloud wrote:
I can totally say...I feel your pain...lol. I have to do endless algebra questions coming outta my kazoo. I only do em cause its part of my school credit :(


btw...I know an odd quote from my physics teacher "Guns don't kill people, physics do" lol
Page: 1 2