World to camera coordinates - math

What is the transformation matrix V that converts points from world coordinates to camera coordinates such that the camera y-axis is the world's y-axis. The camera looks towards the world's x-axis and the camera is located at(5,0,5)?

Check out Finding the Transform matrix from 4 projected points (with Javascript) or Redraw image from 3d perspective to 2d or How to match 3D perspective of real photo and object in CSS3 3D transforms for how to define a map between world plane and camera plane given 4 points and their images. Your preservation of the y axis could translate into preservation of the point at infinity in the y direction, at least if you mean that all parallel lines in the y direction are preserved, not just the single axis. If you move the camera location to the 3d origin, then you can treat the 3d vectors of your world coordinates as homogeneous coordinates in a 2d view of that world by the camera.

Related

projecting points onto the sky

If I had a sphere with unit radius, and I had some points defined as latitudes and longitudes on that sphere, and I had a camera defined with a vertical and horizontal field of view angle which is always in the centre of the sphere. How can I project these points onto that camera?
A point at direction (x,y,z) at infinity has homogeneous coordinates of (x,y,z,0). So assuming that you use a typical view-projection matrices to describe your camera model, it is as simple as calculating
P * V * ( cos(lon)*cos(lat), sin(lon)*cos(lat), sin(lat), 0 )'
and then proceeding with a perspective divide and rasterization.

Converting points on a 3D plane to a 2D coordinate system w.r.t. camera

Please kindly redirect me if this is a repeated question:
Currently I have some points in 3D space projected on a plane, and I would like to convert it to 2D wrt the camera angle/view matrix I am currently at. For instance, the 3D coordinates on the YZ plane are (0,1,4) and (0,4,2), so the change in z is -2. However, I want to flatten this and achieve a change in z of 0. Any help or comments are appreciated!

How to orient a 3D object in relation to its direction and the ground?

In my game I have characters walking around a 3d terrain. The characters treat the terrain however as a 2d game map, so each character has a direction and a rotation on a 2d plane.
I want to rotate the characters as they're walking on the terrain, so that they are oriented to stand in relation to the terrain, rather then always be oriented as if they're walking on flat ground. This with keeping the original direction of the characters.
Basically I want
For each arbitrary x\z (width\depth) point on the game map I have
the (x,y,z) vector of the point on the terrain
The normal of the the specific terrain face related to the point
Using this, how do I set the rotation of the characters to achieve this?
Depending on which axis you would like to rotate the object the dot product of the faces normal with that axis will return you the cosine of the angle between the two vectors. By that angle you would have to rotate your object.

finding the rotation axis

I'm using eigen library to rotate a plane to be parallel to the ground plane.
The ground plane is defined using the normal vector (0,0,1)
The target plane is a set of 3D points and a normal
The rotation angle is known
the normal vector of the plane as well as every point on that plane has to be rotated to be parallel to the ground plane
I'd like to use affine transformation from
http://eigen.tuxfamily.org/api/TutorialGeometry.html
something like this
Transform t = AngleAxisf(a,axis);
axis in this case is a matrix representing an arbitary axis, along which the rotation takes place.
How to find this axis?
Many thanks
Making two planes parallel can be done by making their normals parallel, so you just need to find the axis to rotate the target plane normal about. This is just the axis that is perpendicular to both your ground plane normal and your target plane normal which can be found using the cross product. In your case, if your target plane has a normal of [x,y,z], then the rotation axis is [y,-x,0].

calculate location in virtual radar by gps position and compass

so i got three variables, my location, my target location and the compass heading.
how can i calculate where the target location should be represented on a virtual radar?
i guess i first must calculate the distance between the two gps points and the angle of them relative to north or so. and then there should be a formula with sin or cos to place that point on a coordinate system...?
ps: in javascript...
Start with simpler problems.
In 2D, try converting back and forth between cartesian and polar coordinates. References are available.
Do the same, but for the polar coordinates use an observer who measures angles from some ray that is not in the X direction.
The same, but using an origin for the polar coordinates that is not at {x=0,y=0}.
In 3D, go back and forth between cartesian and spherical coordinates.
Again, with spherical coordinates in an arbitrary orientation, using an arbitrary origin.
Now convert from GPS coordinates (which are spherical) to cartesian, then to radar-centered spherical.

Resources