views:

1421

answers:

7

Hey,

I wish to determine the 2D screen coordinates (x,y) of points in 3D space (x,y,z).

The points I wish to project are real-world points represented by GPS coordinates and elevation above sea level.

For example: Point (Lat:49.291882, Long:-123.131676, Height: 14m)

The camera position and height can also be determined as a x,y,z point. I also have the heading of the camera (compass degrees), its degree of tilt (above/below horizon) and the roll (around the z axis).

I have no experience of 3D programming, therefore, I have read around the subject of perspective projection and learnt that it requires knowledge of matrices, transformations etc - all of which completely confuse me at present.

I have been told that OpenGL may be of use to construct a 3D model of the real-world points, set up the camera orientation and retrieve the 2D coordinates of the 3D points.

However, I am not sure if using OpenGL is the best solution to this problem and even if it is I have no idea how to create models, set up cameras etc

Could someone suggest the best method to solve my problem? If OpenGL is a feasible solution i'd have to use OpenGL ES if that makes any difference. Oh and whatever solution I choose it must execute quickly.

Thanks for your help

+2  A: 

You do indeed need a perspective projection and matrix operations greatly simplify doing so. I assume you are already aware that your spherical coordinates must be transformed to Cartesian coordinates for these calculations.

Using OpenGL would likely save you a lot of work over rolling your own software rasterizer. So, I would advise trying it first. You can prototype your system on a PC since OpenGL ES is not too different as long as you keep it simple.

Judge Maygarden
I wasnt aware I had to transform to cartesian coordinates, so thanks for that.Regarding OpenGL, I think i'll try and implement a solution using it as it has methods to set up the camera position and, I believe, a mechanism to get the 2D projection from the 3D model.Do you know any good tutorials?
These are classic tutorials ported to several languages: http://nehe.gamedev.net/
Judge Maygarden
A: 

If just need to compute coordinates of some points, you should only need some algebra skills, not 3D programming with openGL.

Moreover openGL does not deal with Geographic coordinates

First get some doc about WGS84 and geodesic coordinates, you have first to convert your GPS data into a cartesian frame ( for instance the earth centric cartesian frame in which is defined the WGS84 ellipsoid ).

Then the computations with matrix can take place. The chain of transformations is roughly :

  • WGS84
  • earth centric coordinates
  • some local frame
  • camera frame
  • 2D projection

For the first conversion see this The last involves a projection matrix The others are only coordinates rotations and translation. The "some local frame" is the local cartesian frame with origin as your camera location tangent to the ellipsoid.

fa.
A: 

To fa.

I realise I have to convert from spherical to Cartesian coordinates now, I understand that fine. However, would it be possible to explain the rest of the steps you mentioned, and dumb it down a little ;)

I am going to have to really read around the subject to understand the full process, however all the help I can get to understand each stage would be really appreciated!

I.e. what is the matrix, how do I create it and what is it populated with? What transformations are needed? How do I enter camera information i.e. tilt/rotation/position etc. How do I then get the 2D coordinates?

It would be great if there were a book which explains all this but the ones I have found are confusing/not that helpful.

+2  A: 

I'd recommend "Mathematics for 3D Game Programming and Computer Graphics" by Eric Lengyel. It covers matrices, transformations, the view frustum, perspective projection and more.

There is also a good chapter in The OpenGL Programming Guide (red book) on viewing transformations and setting up a camera (including how to use gluLookAt).

If you aren't interested in displaying the 3D scene and are limited to using OpenGL ES then it may be better to just write your own code to do the mapping from 3D to 2D window coords. As a starting point you could download Mesa 3D, an open source implementation of OpenGL, to see how they implement gluPerspective (to set a projection matrix), gluLookAt (to set a camera transformation) and gluProject (to project a 3D point to 2D window coords).

shouston
+3  A: 

Here's a very general answer. Say the camera's at (Xc, Yc, Zc) and the point you want to project is P = (X, Y, Z). The distance from the camera to the 2D plane onto which you are projecting is F (so the equation of the plane is Z-Zc=F). The 2D coordinates of P projected onto the plane are (X', Y').

Then, very simply:

X' = ((X - Xc) * (F/Z)) + Xc

Y' = ((Y - Yc) * (F/Z)) + Yc

If your camera is the origin, then this simplifies to:

X' = X * (F/Z)

Y' = Y * (F/Z)

endtime
A: 

Okay thanks for all your help; I think i'll take a look at the book mentioned above as it looks like i'll need to brush up on my maths as well as the underlying theory of the problem.

It appears some are suggesting I use OpenGL for this problem and others say writing my own solution is all thats needed...

So what is the better solution OpenGL or write my own?

That depends on what you precisely want to do. In your original question you said you wanted to just calculate a 2D point. Or do you want to draw a map (or similar things) in 3D?
Tobias Müller
No I do not wish to draw anything I just want to determine the 2D x,y screen coords, so that I can determine where on the screen the point in the 3D world intersects.
A: 

Wow, thanks for all your help. I'll spend the next couple of days looking at the resources you have suggested and see where I can go with this.

I'll reply to this thread if I get stuck.

Thanks again!

Stack Overflow is not a forum with "threads". Use "comments" for commenting, not "answers" for commenting.
Ivan Vučica