Sign in to follow this  
TheLogan

How to draw a 3D point on a 2D plane?

Recommended Posts

Hi, I am an AI programmer in a local company and I want to develop my skills more in the 3D programming field. Let's say that I have a 3D Vector of a point, and want to draw this point on a 2D plane. The 3D vector would be: (0,2,8). What would be the 2D coordinate of this point on a plane, and what is the math equation to do it? Thanks all for your help, Steve

Share this post


Link to post
Share on other sites
You mean you want to project the point onto the plane?

Something to this effect:
float distance = plane_normal.Dot( point - any_plane_pos );
point += ( plane_normal * -distance );


Or in English: Get the distance to the plane. Move the point in the negative direction of the plane normal by this distance.

edit: If the plane is 2D (normal is 0,0,1 for instance), then you can project the point onto the plane by simply setting it's z value to zero.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kest
You mean you want to project the point onto the plane?

Something to this effect:
float distance = plane_normal.Dot( point - any_plane_pos );
point += ( plane_normal * -distance );


Or in English: Get the distance to the plane. Move the point in the negative direction of the plane normal by this distance.

edit: If the plane is 2D (normal is 0,0,1 for instance), then you can project the point onto the plane by simply setting it's z value to zero.


So, assuming that the plane is 2D, and that it is located at the position (0, 0) and that the 3D point is located at the Point (0, 2, 8), the 2D location of the 3D point on the plabe would be: (0, -2)?

Based on what you said, I just made an equation, where:
* dist = the distance between the plane and the 3D point
* v3D = the vector of the 3D point
* vPlane = the vector of the plane

Lets assume that the plane can be 3D in that example.

|dist|^2 = (vPlane->x - v3D->x)^2 + (vPlane->y - v3D->y)^2 + (vPlane->z - v3D->z)^2

Do you think that it is good?

By the way, I'll be using this to make my camera system.

Thanks for your comments,
Steve

Share this post


Link to post
Share on other sites
Quote:
Original post by TheLogan
So, assuming that the plane is 2D, and that it is located at the position (0, 0) and that the 3D point is located at the Point (0, 2, 8), the 2D location of the 3D point on the plabe would be: (0, -2)?

Only if the plane normal is xyz (0,0,1 or -1). If z is "into the screen" in your 2D view, then simply smashing the z value on your 3D coordinates will map them to that view.

Quote:
|dist|^2 = (vPlane->x - v3D->x)^2 + (vPlane->y - v3D->y)^2 + (vPlane->z - v3D->z)^2

It looks fine, but you generally don't want to square this distance. If the distance is negative, then the point is resting on the opposite side of the plane, and needs to be moved in the opposite direction to project it. So just..
dist = (vPlane->x - v3D->x) + (vPlane->y - v3D->y) + (vPlane->z - v3D->z)

I guess distance is a bad name for it. Maybe offset would have been better. If you negate this value and multiply the plane normal with it, you get the exact amount to move the coordinate to place it on the plane. Well, as long as the plane runs through the zero point in your coordinate system.

Share this post


Link to post
Share on other sites

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