# adding points in a plane

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

## Recommended Posts

Hello, I have a pure mathematic question. I am out calculated. Imagine I got a 3d point P in a plane describe by three points. If i wanna add a new point Pnew on a distance R from P, then his is not correct: Pnew.x=P.x+d*cosf(angle); Pnew.y=P.y+d*sinf(angle); Pnew.z=P.z; How can i do that? Another math question is:i wanna calculate the intersection points between 2 circles. The two circles lay in the same plane describe by three 3d points. I found the intersection in 2d, but i dont know how to calculate it now in 3d. I hope someone can help me.

##### Share on other sites
Just a small suggestion. I'd say the easiest way to store and work with planes is in vector-distance format, where you store two elements - the plane normal, and the distance from the origin. This way you can uniquely describe a plane by its orientation and position. It also makes other common calculations easier with the plane. If you want, you can store a whole orthonormal basis which would also include an "up" and "right" vector so you don't have to calculate then all the time.

As for finding the intersection of two circles in the same plane, simply generalize the calculations you were doing before in 2D. That's simply a 3D space where your normal is (0,0,1), your "up" is (0,1,0), and your "right" is (1,0,0). A point's "x" distance would be the dot product between the point vector and the "right" vector, and the point's "y" distance would be the dot product between the point and the "up" vector. No need to worry about the normal really, since the circles are already projected onto the plane.

##### Share on other sites
I thought to do it as follow:

Take the point P as origin for a local coordinatesystem.
The normal of the Plane is the local Z-axis.
Local X-axis is the perpendicular on the Z-axis.
Local y-axis is the crossproduct between the local x-axis and local z-axis.
Transform all points to this local coordinatesystem.

But: - how do you calculate the perpendicular on a vector?
- how do you transform a point to a local coordinate system?
- Do you have to normalize the local axes?

Greetz
takis

##### Share on other sites
Quote:
 Original post by takis- how do you calculate the perpendicular on a vector?

I have to admit this process is rather dependent on what information you have, and whether the orientation of your orthonormal basis is important. For just finding the intersection between circles, the basis isn't important as the mathematics will still work and you can easily transform into another more relevant basis. So in this case you would probably generate a random vector first, find the cross product between this random vector and the normal, and label the result as either "right" or "up". Then take the cross product of this new vector and the normal, and you have the final "right" or "up" (the one you didn't chose the first time). It may seem arbitrary, but that's pretty much what you have to do in the absence of other information. The other case is when you have additional information, such as when the normal is connected to a polygon face. Then you have extra points you can use to generate a meaningful basis, like if a texture space orientated to the polygon is involved.

Quote:
 - how do you transform a point to a local coordinate system?

If your point is in world space, then the transformation matrix is simply composed of your local coordinate system basis. If your point is in another arbitrary basis already, then you need to first multiply the point by the inverse transformation matrix so you get the point back into world space (or more generally, the basis of which your other local basis is defined). And that's when it gets confusing, since your local coordinate system is really defined relative to another basis, usually the world. However, in some model formats this local basis can be define relative to another local basis, which is defined relative to another local basis, etc., which eventually is defined relative to the world. You can picture it hierarchically like a tree, where each level is another transformation, and in order to go down another branch you need to first go up to the parent node. So if you have this transformation hierarchy:
          A         / /                B   C

And you want to get to B from C, you first need to inverse transform from C to A, and then forward transform from A to B. Now A can either be world space, which is the root, or some other space which has even more parents. If it's confusing now you just need to spend a bunch of time dealing with it, and eventually it should make some sense.

Quote:
 - Do you have to normalize the local axes?

Yes, the axis should be normalized, however you don't have to do that until you actually find all three of them. The cross product will still have the behavior of generating perpendicular vectors regardless of length. So save yourself some computation and only do it at the end. In all cases, you'll have to watch out for any of your vectors being too small, like if you happen to generate that random vector and it's almost equal to your normal, then your cross product will be really really short, which could introduce float-point errors. Then you might need to normalize prematurely, and then again at the very end.

##### Share on other sites

Z-Axis: Plane normal
Y-Axis (for example) ... take one of your polygon edges ( v.e. Point1 - Point2), normalize the resulting vector
X-Axis: Cross product of Z and Y axis (perpendicular vector)

Transforming points into local system:
Say local system is for point P, you want to transform another Point A into the System X, Y, Z around P.
You then do:
R = A - P
then:
newx = R dot X;
newy = R dot Y;
newz = R dot Z;
note that X, Y, Z are required to be unit length here.

Imagine if i wanna add a new point Padd on a distance d from P but still on the plane. After creating the local system with P as origin:

Transformin Padd back to global gives me:

Is this Right?

##### Share on other sites
a simple way to do it, if direction from point P isn't important, is to subtract two of points that define the plane - you get a vector that is parallel to the plane.
Now, normalize that vector and multiply it by R, add to P and you have your second point in the plane R distance from P.

##### Share on other sites
Quote:
 Original post by takisWhat about this:Z-Axis: Plane normalY-Axis (for example) ... take one of your polygon edges ( v.e. Point1 - Point2), normalize the resulting vectorX-Axis: Cross product of Z and Y axis (perpendicular vector)Transforming points into local system:Say local system is for point P, you want to transform another Point A into the System X, Y, Z around P.You then do:R = A - Pthen:newx = R dot X;newy = R dot Y;newz = R dot Z;note that X, Y, Z are required to be unit length here.

That's correct. Usually these operations are concatenated into a single transformation matrix that you multiply the point vector by to achieve your result. For example, if you take your translation matrix and multiply it by your space transformation matrix, you'll end up with the final transformation matrix that does everything you need:
| 1    0    0    0 |   | X.x  Y.x  Z.x  0 || 0    1    0    0 | * | X.y  Y.y  Z.y  0 | = Final transformation matrix (T)| 0    0    1    0 |   | X.z  Y.z  Z.z  0 || -P.x -P.y -P.z 1 |   | 0    0    0    1 || A.x  A.y  A.z  1 | * T = Final transformed point

If you do the multiplication long-hand you will see the mechanics of the calculations are the same as what you have.

##### Share on other sites
How can you put a point in local system back in global coordinates without using matrix multiplications?

[Edited by - takis on March 15, 2005 7:15:55 AM]

##### Share on other sites
what is the inverse of the matrix below?

|xx yx zx 0|
|xy yy zy 0|
|xz yz zz 0|
|t1 t2 t3 1|

##### Share on other sites
Quote:
 Original post by takisHow can you put a point in local system back in global coordinates without using matrix multiplications?

Keep in mind that any point P can be represented as: P = xi + yj + zk. x, y, and z are your local coordinates, and i, j, and k define your local basis. So if you actually go ahead multiply through to get P, you will have your point in world space, or whatever space i/j/k are defined in.

Quote:
 what is the inverse of the matrix below?|xx yx zx 0||xy yy zy 0||xz yz zz 0||t1 t2 t3 1|

Matrix Inverse, although the page here actually describes a process rather than give just a definition.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 14
• 45
• 22
• 27
• ### Forum Statistics

• Total Topics
634042
• Total Posts
3015204
×