How to Convert Cartesian XYZ ( ECEF ) Coordinates to Apple Metal XYZ Coordinates - swift

I am working on a 3D application where I display satellites above a 3d sphere using Apple Metal and Swift on iOS.
I have my 3D XYZ Coordinates of a satellite in ECEF format, where Z is pointing 'up', and X and Y are in the equatorial plane. I am confident of these coordinates and verified them.
Metal has a difference coordinate system, however, where Z is pointing perpendicular to the display.
I can place my satellite in Swift at the ECEF XYZ coordinates, but obviously they are in the wrong location with respect to the earth's actual coordinates, where Z is 'up'. I have verified this with various other sources of truth.
I have searched extensively for a method on how to 'rotate' ECEF/cartesian XYZ coordinates with 'Z' up into the Metal/OpenGL right-handed coordinate system. Unfortunately, I have not yet found a working solution.
I have tried flipping the various axes and swapped rows in my projection and modelview matrices.
How can I take take my XYZ coordinates with Z as 'up' and convert them into the proper valeus for the Metal XYZ coordinate sytem?

Related

Find 3D coordinate with respect to the camera using 2D image coordinates

I need to calculate the X,Y coordinates in the world with respect to the camera using u,v coordinates in the 2D image. I am using an S7 edge camera to send a 720x480 video feed to MATLAB.
What I know: Z i.e the depth of the object from the camera, size of the camera pixels (1.4um), focal length (4.2mm)
Let's say the image point is at (u,v) = (400,400).
My approach is as follows:
Subtract the pixel value of center point (240,360) from the u,v pixel coordinates of the point in the image. This should give us the pixel coordinates with respect to the camera's optical axis (z axis). The origin is now at the center of the image. So new coordinates are: (160, -40)
Multiply the new u,v pixel values with pixel size to obtain the distance of the point from the origin in physical units. Let's call it (x,y). We get (x,y) = (0.224,-0.056) in mm units.
Use the formula X = xZ/f & Y = yZ/f to calculate X,Y coordinates in the real world with respect to the camera's optical axis.
Is my approach correct?
Your approach is going in the right way, but it would be easier if you use a more standardize approach. What we usually do is use Pinhole Camera Model to give you a transformation between the world coordinates [X, Y, Z] to the pixel [x, y]. Take a look in this guide which describes step-by-step the process of building your transformation.
Basically you have to define you Internal Camera Matrix to do the transformation:
fx and fy are your focal length scaled to use as pixel distance. You can calculate this with your FOV and the total pixel in each direction. Take a look here and here for more info.
u0 and v0 are the piercing point. Since our pixels are not centered in the [0, 0] these parameters represents a translation to the center of the image. (intersection of the optical axis with the image plane provided in pixel coordinates).
If you need, you can also add a the skew factor a, which you can use to correct shear effects of your camera. Then, the Internal Camera Matrix will be:
Since your depth is fixed, just fix your Z and continue the transformation without a problem.
Remember: If you want the inverse transformation (camera to world) just invert you Camera Matrix and be happy!
Matlab has also a very good guide for this transformation. Take a look.

Distance between two point along the cylinder surface

How to find out distance between point along the surface from one point to all other point on the cylinder surface.
XYZ coordinates of points are known
e.g
suppose 4 points are there on the surface of the cylinder here i want to find out following data i.e distance between point(1-2),point(1-3),point(1-4),point(2-3),point(2-4),point(3,4) along the surface.H
What you are looking for is the geodesic of a cylinder. Since you mentioned Matlab in the tag, you can use this tool

Understanding depth values in 3D point cloud

I have problems understanding the depth (Z) value in 3D point cloud resulted from 3d sparse reconstruction like this example in MATLAB: http://www.mathworks.com/help/vision/ug/sparse-3-d-reconstruction-from-multiple-views.html
I have attached a picture showing the reconstructed 3D point cloud in the above example. I have put some datatips on the figure so we know the (x,y,z) coordinates of the points. here are my questions:
1- what does the Z value in point cloud represent? is it the distance in millimeters from the camera? if that's the case then it does not make sense based on the picture I attached since I am sure the distance of the sphere and checkerboard from the camera must be greater than 200 mm.
Or maybe it is from some reference point in space? then what is this reference point? and how can I make a 3D point cloud that the Z values indicate the distance from the camera?
2- why is there negative values for Z? what does that mean in terms of distance to the camera?
I appreciate if someone can explain.
In this example the world coordinates are defined by the checkerboard. The checkerboard defines the X-Y plane, and the Z-axis points into the checkerboard, as explained in the documentation:
Since your 3D points are above the checkerboard, they have negative Z-coordinates.
Your (x,y,z) coordinates are in world units, which are completely disconnected from metric values (unless you build a scale between world and metric, there are various methods to do it). So the z value tells you about the depth of each point in world coordinates.
If you have the pose of each camera, and you multiply each point by the camera projection matrix, you will get the (x',y',z') points in camera coordinates. At that point, if z' is negative, it means it's behind the camera.

Kinect - Calculating Surface Area

I'd like to be able to calculate the surface area of objects seen by the depth camera. Is there an easy way to do this? For example if the kinect is seeing a player I need to calculate how much surface it is covering.
If there is no such functions existing, I can calculate by creating multiple squares with coordinate (x,y) (x+1,y) (x, y+1) (x+1, y+1) and taking into consideration the z value. But I'm not sure how to get the distance in mm or cm between pixels in the x or y axis.
Thanks

iPhone opengl es: Touch detection

I have been messing around with opengl es on the iphone and right now I have some cubes on the screen. Currently I am trying to detect touches on these cubes. After a lot of searching on google this is what I have so far
Use gluUnProject to find the x,y cordinates on the near plane in the world cordinate system
Use gluUnProject to find the x,y cordinates on the far plane in the world cordinate system
Subtract the vector obtained in 2 from the vector obtained in 1 to obtain the direction vector
Normalize the direction vector to obtain the unit vector
Iterate through all the trianlges and use the ray-triangle intersection to check if the ray intersects this triangle
I think my mistake is in step 5. I have a feeling I am supposed to transform my triangles by the modelview matrix? Is my assumption correct? If yes any clues how to transform a triangle (an array of 3 floats) by the modelview matrix (an array of 16 floats)