Measuring distance
by Aidan Sliney · in Technical Issues · 07/21/2008 (4:22 am) · 11 replies
I can get two points on an object p1 =x1y1z1 and p2 = x2y2z2 so i can measure the distance between them if they are both on the same plane.
But how can i measure the distance between two points on an object if there is an angle between them.
For example: an L-shaped wall. p1 is on the outer left of the L. p2 is on the outer bottom of the L.
if i had the point of the corner i could do: p1 to corner + corner to p2 = full distance : but i Have no way of getting the corner point.
How can I measure the distance between the two points going along the wall?
But how can i measure the distance between two points on an object if there is an angle between them.
For example: an L-shaped wall. p1 is on the outer left of the L. p2 is on the outer bottom of the L.
if i had the point of the corner i could do: p1 to corner + corner to p2 = full distance : but i Have no way of getting the corner point.
How can I measure the distance between the two points going along the wall?
#2
the answer should be:
dx = Ax-Bx
dy = Ay-By
dz = Az-Bz
distance = sqrt(dx*dx + dy*dy + dz*dz)
[edited due to completely borked mathematics]
07/21/2008 (11:16 pm)
Oops - I had this way wrongthe answer should be:
dx = Ax-Bx
dy = Ay-By
dz = Az-Bz
distance = sqrt(dx*dx + dy*dy + dz*dz)
[edited due to completely borked mathematics]
#3
We dont know d or the angle made at d
a-------------b
| |
| v
| |
| |
| |
c---------w--- d
or
a-------------b
\ \
\ v
\ \
\ \
\ \
c---------w--- d
07/22/2008 (3:00 am)
Hey. Below is what i mean. trying to get the distance from v to w with both having an xyz.We dont know d or the angle made at d
a-------------b
| |
| v
| |
| |
| |
c---------w--- d
or
a-------------b
\ \
\ v
\ \
\ \
\ \
c---------w--- d
#4
|
v
|
|
|
should be connecting b to d.
Also the distance i am looking for is not the direct distance between the two points but the distance around the wall.
I think it is impossible!!
07/22/2008 (4:15 am)
It didn't show up right on the above comment|
v
|
|
|
should be connecting b to d.
Also the distance i am looking for is not the direct distance between the two points but the distance around the wall.
I think it is impossible!!
#5
There's a console function for this called VectorDist (defined in math/mathTypes.cpp). VectorF is esentially the same as Point3F.
07/22/2008 (4:46 am)
If you know the exact 3d positions of v and w then to get the distance between them:VectorF v, w; // assign values VectorF vdist = w - v; F32 distance = mSqrt((vdist.x * vdist.x) + (vdist.y * vdist.y) + (vdist.z * vdist.z));
There's a console function for this called VectorDist (defined in math/mathTypes.cpp). VectorF is esentially the same as Point3F.
#6
07/22/2008 (5:15 am)
This will give me the distance ads the crow flies. i need the distance around d!!
#7
07/22/2008 (5:22 am)
Oh I see... So then what are the known values?
#8
07/22/2008 (7:14 am)
W and v only. I assume that i dont have enough values to do this!!
#9
Also, are the objects that must be avoided always static?
07/22/2008 (7:36 am)
It depends.. what do you want to achieve with this? Why do you need this distance? Is it for moving AI or is it for something else? Maybe it could be done through some tweaked A* algorithm?Also, are the objects that must be avoided always static?
#10
07/22/2008 (8:00 am)
It is an actual wall. the user puts a nail into the wall(w) goes around the corner puts a nail in the other wall(v). I nedd the distance around the wall between the two nails
#11
If you can't get the angles of V and W, I don't think you don't have enough information to do this. You can't figure out two sides of a triangle if the only thing you know is the third.
07/22/2008 (8:39 am)
If you know the angles of V and W, you could do this: (The code is psuedo-code)AngleD = 180 - (AngleW + AngleV); DistVD = Sin(AngleW) * DistVW / Sin(AngleD); DistWD = Sin(AngleV) * DistVW / Sin(AngleD); TotalDist = DistWD + DistVD;
If you can't get the angles of V and W, I don't think you don't have enough information to do this. You can't figure out two sides of a triangle if the only thing you know is the third.
Associate James Ford
Sickhead Games
It sounds like you want to know the distance from point p to the edge bd plus the distance of that projected point to point d. So you need to calculate a points distance from a segment...
I have not personally written a Torque version of this calculation, but I'm sure you can find a more generic C++ version somewhere on the internets...
www.google.com/search?q=point+distance+to+segment&sourceid=navclient-ff&ie=UTF-8...