Sign in to follow this  

how to find out the point is between two parallel vectors?

This topic is 3592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

for example i have two vectors v1(x1,y1,z1),v2(x2,y2,z2) and a point p(x3,y3,z3).how can i learn where the point is? between the vectors or not? (in 3d).it is not important that the point is at the same level with vectors.for example v1=(0,0,1) v2=(2,0,4) p=(1,5,6) p is between the vectors' directions but not at the same level because y=5 and z=6.(this is simple because the direction is through z axis) i wish i could explained the problem

Share this post


Link to post
Share on other sites
Just a guess but first get new vectors from the bases of the old vector to the new point. Now project the new vectors on to the old vectors. if the projection is shorter than the old vector the point could be between the vectors. You will also need to check that the angle between the new vector and the original vector points in the "right" direction.

Share this post


Link to post
Share on other sites
Vectors are either a direction, in which case their 'position' is meaningless, or they represent a point and 'direction' is meaningless.

Trying to find a position relating to vectors assumes that at least one vector is a position representation, yet you say the vectors must be parallel (which is meaningless).

Can you draw us a picture instead?

Share this post


Link to post
Share on other sites
part of cube-sphere collision detector.sphere is randomly producing because of this i want to learn where the sphere is according to cube (upper surface,bottom surface,corner.....?)

Share this post


Link to post
Share on other sites
Are you asking how to determine if a point lies within a 'wedge' formed by two vectors, with the point and the vectors projected to a cardinal plane? Something like:

\ /
\ * (in) /
\ /
\ / * (out)
\ /
\/
?

Share this post


Link to post
Share on other sites
Quote:
Original post by nkjsat2
part of cube-sphere collision detector.sphere is randomly producing because of this i want to learn where the sphere is according to cube (upper surface,bottom surface,corner.....?)
There are established algorithms for performing this sort of test. For a simple Boolean test, compute the point on the cube closest to the sphere center and compare the distance from the sphere center to this point to the sphere radius. (It's also possible to compute collision information - i.e. contact manifold and normal - using this method.)

Share this post


Link to post
Share on other sites
if you look Square-sphere collision section at
http://petesqbsite.com/sections/express/issue24/Time_based_motion_&_Collision_detection.htm

we can learn the position of the point with
/////////////////////
IF spherex < squarex1 THEN

xc = 1

ELSEIF spherex < squarex2 THEN

xc = 2

ELSE

xc = 3

END IF
/////////////////////
but in 3d comparing points is not working because of this i want to use vectors

Share this post


Link to post
Share on other sites
Quote:
Original post by nkjsat2
if you look Square-sphere collision section at
http://petesqbsite.com/sections/express/issue24/Time_based_motion_&_Collision_detection.htm

we can learn the position of the point with
/////////////////////
IF spherex < squarex1 THEN

xc = 1

ELSEIF spherex < squarex2 THEN

xc = 2

ELSE

xc = 3

END IF
/////////////////////
but in 3d comparing points is not working because of this i want to use vectors
The algorithm is the same in 3-d as it is in 2-d.

I see what you're trying to do (classify the point with respect to two edges that meet at a corner), but this is the wrong way to think about it. What you're really doing is classifying the point with respect to the hyperplanes (lines in 2-d, planes in 3-d) that define the box. Classifying the point with respect to each of these hyperplanes tells you in which Voronoi region (the differently colored areas in the diagrams in the article you linked to) the point falls.

That said, I think the method presented in the article is a bit overly complicated. Here's a more straightforward method:
bool IntersectSphereBox(vector3 center, float radius, vector3 min, vector3 max)
{
vector3 closest = center;
for (int i = 0; i < 3; ++i) {
closest[i] = min(max(closest[i], min[i]), max[i]));
}
return length(closest - center) < radius;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
Quote:
Original post by nkjsat2
if you look Square-sphere collision section at
http://petesqbsite.com/sections/express/issue24/Time_based_motion_&_Collision_detection.htm

we can learn the position of the point with
/////////////////////
IF spherex < squarex1 THEN

xc = 1

ELSEIF spherex < squarex2 THEN

xc = 2

ELSE

xc = 3

END IF
/////////////////////
but in 3d comparing points is not working because of this i want to use vectors
The algorithm is the same in 3-d as it is in 2-d.

I see what you're trying to do (classify the point with respect to two edges that meet at a corner), but this is the wrong way to think about it. What you're really doing is classifying the point with respect to the hyperplanes (lines in 2-d, planes in 3-d) that define the box. Classifying the point with respect to each of these hyperplanes tells you in which Voronoi region (the differently colored areas in the diagrams in the article you linked to) the point falls.

That said, I think the method presented in the article is a bit overly complicated. Here's a more straightforward method:
bool IntersectSphereBox(vector3 center, float radius, vector3 min, vector3 max)
{
vector3 closest = center;
for (int i = 0; i < 3; ++i) {
closest[i] = min(max(closest[i], min[i]), max[i]));
}
return length(closest - center) < radius;
}


This warrants some explanation:

The loop takes a temporary value that starts at the center of the sphere and clamps the X, Y, and Z values (separately) to a value within the mininum and maximum limits of the box in that dimension.

This results in a point in the box that is closest to the sphere. Then you just use a 3D distance comparison to see if the sphere is large enough to enclose the closest point.


Optimization: You can use "return LengthSquared(closest - center) < radius * radius;" to avoid having the square-root in the length function.

Length squared of a vector is simply (x*x + y*y + z*z).

Share this post


Link to post
Share on other sites
Quote:
Original post by Nypyren
Quote:
Original post by jyk
Quote:
Original post by nkjsat2
if you look Square-sphere collision section at
http://petesqbsite.com/sections/express/issue24/Time_based_motion_&_Collision_detection.htm

we can learn the position of the point with
/////////////////////
IF spherex < squarex1 THEN

xc = 1

ELSEIF spherex < squarex2 THEN

xc = 2

ELSE

xc = 3

END IF
/////////////////////
but in 3d comparing points is not working because of this i want to use vectors
The algorithm is the same in 3-d as it is in 2-d.

I see what you're trying to do (classify the point with respect to two edges that meet at a corner), but this is the wrong way to think about it. What you're really doing is classifying the point with respect to the hyperplanes (lines in 2-d, planes in 3-d) that define the box. Classifying the point with respect to each of these hyperplanes tells you in which Voronoi region (the differently colored areas in the diagrams in the article you linked to) the point falls.

That said, I think the method presented in the article is a bit overly complicated. Here's a more straightforward method:
bool IntersectSphereBox(vector3 center, float radius, vector3 min, vector3 max)
{
vector3 closest = center;
for (int i = 0; i < 3; ++i) {
closest[i] = min(max(closest[i], min[i]), max[i]));
}
return length(closest - center) < radius;
}


This warrants some explanation:

The loop takes a temporary value that starts at the center of the sphere and clamps the X, Y, and Z values (separately) to a value within the mininum and maximum limits of the box in that dimension.

This results in a point in the box that is closest to the sphere. Then you just use a 3D distance comparison to see if the sphere is large enough to enclose the closest point.


Optimization: You can use "return LengthSquared(closest - center) < radius * radius;" to avoid having the square-root in the length function.

Length squared of a vector is simply (x*x + y*y + z*z).


i am a medical student and i am new in 3d world.can you make this explanation more simple.for example is closest[0]=x closest[1]=y closest[2]=z ? an example may be more helpful for "closest[i] = min(max(closest[i], min[i]), max[i]))"

thank you.

Share this post


Link to post
Share on other sites
Quote:
i am a medical student and i am new in 3d world.can you make this explanation more simple.for example is closest[0]=x closest[1]=y closest[2]=z ?
Yes, that's right.
Quote:
an example may be more helpful for "closest[i] = min(max(closest[i], min[i]), max[i]))"
If you're programming in C++, the 'min' and 'max' functions are in the algorithm header. Otherwise, they can be implemented as follows (written for clarity):
// T represents the type that you're working with (such as floats
// or ints). (In the standard library these functions are implemented
// as function templates, and so will work with any type for which
// the appropriate operators are defined.)


T min(T a, T b) {
if (a < b) {
return a;
} else {
return b;
}
}

T max(T a, T b) {
if (a > b) {
return a;
} else {
return b;
}
}

Share this post


Link to post
Share on other sites

This topic is 3592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this