#### Archived

This topic is now archived and is closed to further replies.

# 3D & 4D Vector Math

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

## Recommended Posts

How do i take the dot product of a 3D Vector and a 4D plane vector?

##### Share on other sites
Haven't done anything with 4D vectors, but let's say you were given a 3D vector that is (2, -3, 1). To make that vector 4D, shouldn't it be (2, -3, 1, 0)? For example, the vector (2, 3) is the same thing as the 3D vector (2, 3, 0).

So by adding a 0 to your 3D vector, it should be a 4D vector, and you can then apply the dot product to it. Not too sure on this one though, so feel free to correct me anyone.

[edited by - Apocalypse_Demon on December 7, 2002 2:14:01 PM]

##### Share on other sites
VECTOR3(x,y,z) = VECTOR4(x,y,z,1)
PLANE(a,b,c,d), so...

PLANE DOT VECTOR4 = a*x + b*y + c*z + d*1

In my implementation, PLANE is derived from VECTOR4, and I define
float DOT(const VECTOR4& lhs, const VECTOR4& rhs), which allows
a dot product with vcetors or planes in any combination.

##### Share on other sites
quote:
Original post by Anonymous Poster
VECTOR3(x,y,z) = VECTOR4(x,y,z,1)

Why would it have a 1 in the end? Wouldn''t it have a zero instead? For example, a 2D vector(having no depth obviously) could be made into a 3d vector by adding a 0 to the z coordinate. If adding 1, it''s not the same vector and depth is added...

##### Share on other sites
In a purely mathematical sense I don''t think one can perform dot products between vectors of different dimensions.

Of course we can state that xi+yj+zk = xi+yj+zk+0w (where x,y,z is the 3 vector and i,j,k,w are the basis vectors).

But in computer graphics this usually isn''t the case. I think you are trying to find the distance of a point (the 3 vector) and a plane (the 4 vector). In this case the "4th" node of the 3vector will be 1. So if the 3vector is (x,y,z,1) and the 4vector is (a,b,c,d) the formula to compute the distance is:

distance = ax + by + cz + d

- Mikko Kauppila

##### Share on other sites
How does the 4D vector representation of plane (A,B,C,D) relate to the coefficients of the plane equation?

Ax + By + Cz + D = 0

If A, B, and C are the x, y, and z coefficients respectively, and D is the distance from the plane to the origin, then the dot product between the 4D representation of the point (x,y,z,1) and 4D plane representation (A,B,C,D) won''t result in the correct distance. This would be:

Ax + By + Cz + D

Like you said. But if D represents the distance of the plane, we should be subtracting it, not adding it, from the normal 3D dot product. Instead of (a,b,c,d), we should use (a,b,c,-d).

It all comes down to making sure signs stay correct

##### Share on other sites
Sorry i''m kinda lost here, do i substitute a 0 or a 1 on the end of my 3D vector?

##### Share on other sites
depends on what it represents.. if its a position (a point), its a 1.
if its a direction ("aka vector"), its a 0.

some ideas:
point a,b; both with their x,y,z,1

vector to_b = b - a; is
to_b.x = b.x - a.x;
to_b.y = b.y - a.y;
to_b.z = b.z - a.z;
to_b.w = b.w - a.w;
=> to_b.w = 0;

if you want to know the distance of a point to a plane, you calculate

distance = Ax + By + Cz + D, wich, if the point is, as i suggested, x,y,z,1, a 4d dotproduct against the plane (wich is (A,B,C,D) = (x,y,z,w))

point = (x,y,z,1)
direction = (x,y,z,0)

"take a look around" - limp bizkit

##### Share on other sites
Well i''m trying to use a ray tracing algoritm to test if a ray intersects an arbitry plane that a triangle lies in. In my book it says that if the plane vector L dot product with the ray endpoint Q

L.Q = 0 then no intersection occurs.

The problem is that L.Q never seems to equal zero even when i ,ake sure that no intersection will take place.

##### Share on other sites
Could this be my problem? I am using this equation as the deffinition of a ray :

p(t) = Q + tV

i am assuming that Q is the rays endpoint (i.e its position) and V is the direction it will travel in forever. Is this true?

##### Share on other sites
L.Q is nearly never zero, that makes much sence.. think about it.. inprecice floatingpoint values of vectors, how big is the chance that they point into exactly the same direction? not really big..

still the chance is there. but, as i said, nearly zero

"take a look around" - limp bizkit

##### Share on other sites
quote:
Well i'm trying to use a ray tracing algoritm to test if a ray intersects an arbitry plane that a triangle lies in. In my book it says that if the plane vector L dot product with the ray endpoint Q

L.Q = 0 then no intersection occurs.

The problem is that L.Q never seems to equal zero even when i ,ake sure that no intersection will take place.

Think of it this way. Let's say your ray starts out on the positive side of the plane, and that it is going to intersect the plane. As you increase your time steps and check the point, L.Q will remain positive for a while, but slowly decrease. Now, at one time step, it might be a positive number, but all of a sudden, at the next timestep, it's a negative number. This means that the ray HAD to pass through the plane between those two timesteps.

It won't ever exactly be zero, but you can use the sign of the last dot product to determine if the side changed which indicates collision. To determine the actually intersection point, you'll need to use some vector math. It involves using similar triangles

[edited by - Zipster on December 8, 2002 2:31:37 PM]

##### Share on other sites
Another problem i can forsee here is that a ray is considered to be infinite and therefore when i test to see if the ray intersects any of my models triangles i only want the ray to be a small distance long (the distance the player moves in one pass) how can i alter my calculations to make my ray a set distance in length?

##### Share on other sites
ray(t) = origin + t*direction

if you have an intersection, you have the t for it. check if t is in the range you want it to be..

"take a look around" - limp bizkit

##### Share on other sites
If i use the origin in this calculation how will i make my vector point in the right direction? i can''t just use the 2nd end point of my ''ray'' (i know its not strictly a ray in this case) as the direction anymore.

Also should my direction vector be normalised?