#### Archived

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

# 3D & 4D Vector Math

This topic is 5646 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?

• 9
• 13
• 41
• 15
• 12