3D to mobile 2D coordinates

All about geometry

3D to mobile 2D coordinates

Postby Guest » Tue Feb 21, 2017 6:48 am

Hi all,
I need help with a geometry problem for a computer program that I am developing:

Image

  • I work in a 3D (x,y,z) Euclidian space - origin OO.
  • Within this space there is a 2D Euclidian plane with its own independent (x,y) coordinates system.
  • The 2D plane can be positioned anywhere within the 3D space.
  • Point A is defined by the intersection of a raycast form the 3D origin and the 2D plane.
  • I am able to get the 3D (x,y,z) coordinates of A and O, so I can compute the lengths [OO,A] and [OO,O].

I need to get the position of A within the 2D space,ie A(x,y).

I might be able to get more data from my 3D engine, as I believe this is not quite enough? I'm losing my hair over this, I would really appreciate help working out how to go about this...

ps: I'm new here, let me know if I posted this in the wrong place?





Guest
 

Re: 3D to mobile 2D coordinates

Postby Guest » Wed Feb 22, 2017 7:26 am

You are missing information necessary to solve the problem. You need to define the directions of 2D_X and 2D_Y (without this information the idea of 2D coordinates makes no sense).

There are a few different ways to do what you want, but perhaps the easiest way is to actually make things slightly more complicated by introducing a 2D_Z.

Let 2D_X, 2D_Y and 2D_O be (three dimensional) vectors describing the directions of the x, y axis and the origin of the plane in the world coordinates of the 3d space it lives in. So given 2d coordinates (a,b) this would translate into 3d world coordinates given by the components of the vector
a 2D_X + b 2D_Y + 2D_O

We can create a 2D_Z vector which is perpendicular to both 2D_X, and 2D_Y, by taking the cross product of 2D_X and 2D_Y. Now we can represent positions anywhere in 3d space using our new "2D" coordinate system. So (a,b,c) in our new system represents the position
a 2D_X + b 2D_Y + c 2D_Z + 2D_O
in our old system. So now our problem is simply one of changing between two 3d coordinate systems, because we have A in our old coordinate system and we want to know its coordinates in our new system (at which point we can throw away its "z-coordinate" to get the 2d coordinates we actually want).

I'm sure there are lots of tutorials online that will show you how to solve this, and if you are using a 3d library/engine then it probably already has a builtin way of doing this for you. For completeness I'll explain how you can do this since it is not too hard.

Recall that (a,b,c) in our new system represents the position
a 2D_X + b 2D_Y + c 2D_Z + 2D_O
in our old system. This can be more simply represented using matrices. Let M be a 3 by 3 matrix whose columns are 2D_X, 2D_Y, and 2D_Z (in that order). Let vector u be (a,b,c)^T (i.e. the position vector in our new system), and let v be the position vector in our old system. With these definitions we have
M u + 2D_O = v
We explicitly know M, 2D_O and v (the position vector of A in the old system), and we want to work out u. So we re-arrange to get
u = M^-1 (v - 2D_O)
where M^-1 is the inverse of matrix M (it will always exist). See
https://www.mathsisfun.com/algebra/matr ... ugate.html
for a way to find the inverse of a matrix (or search online there are lots of examples).

Hope this helped,

R. Baber.

Guest
 

Re: 3D to mobile 2D coordinates

Postby Guest » Fri Feb 24, 2017 7:06 am

Also it is worth mentioning that if certain conditions are met then it is a lot simpler to calculate the 2d coordinates.

If
2D_X and 2D_Y are unit vectors (i.e. have magnitude 1)
and
2D_X and 2D_Y are orthogonal (i.e. at right angles to each other)
and
A lies on the plane
then the 2d coordinates are simply
2D_X dot producted with (A-2D_O)
and
2D_Y dot producted with (A-2D_O)

Hope this helps,

R. Baber.

Guest
 

Re: 3D to mobile 2D coordinates

Postby Guest » Mon Feb 27, 2017 12:33 pm

Thank you very much Mr. Raber.

Guest
 


Return to Geometry



Who is online

Users browsing this forum: No registered users and 1 guest

cron