Cylindrical projection to sphere - matlab

I have a 2d array (lat*long) containing height information. I want to map this cylindrical projection to a actual sphere with radius r and plot it.
How would I do that? Sorry it so little info, but I'm completely lost right now ...

Longitude and latitude are not cylindrical coordinates; rather, they are equivalent to azimuth and elevation in spherical coordinates. At each latitude and longitude, you have a height (which may need to have the mean radius of the sphere added to it if it isn't the true height from the center already).
Check out the sph2cart function, which converts from spherical to cartesian coordinates. You'll have to convert from degrees to radians first.
Steps to take:
Create matrix (same size as original) with just longitudes.
Do the same for just latitudes (after this you should have 3 matrices of the same size as your original - latitude, longitude, height).
Make sure those latitude and longitude matrices are in
radians, not degrees
Make sure your height info is from the
center of the sphere
Use sph2cart to get x,y,z matrices.
Use surf(x,y,z) to plot the results
Notes on sph2cart from the documentation:
[x,y,z] = sph2cart(azimuth,elevation,r) transforms the corresponding
elements of spherical coordinate arrays to Cartesian, or xyz,
coordinates. azimuth, elevation, and r must all be the same size (or
any of them can be scalar). azimuth and elevation are angular
displacements in radians from the positive x-axis and from the x-y
plane, respectively.

Related

How to convert cartesian to spherical coordinates for hotspots on a 360 image

I have an equirectangular 360 image which will have hotspots mapped onto it in standard X/Y coordinate space.
In Unity, this image will be mapped to a sphere, and I will position the hotspots to the inner surface of the sphere.
I need the Math for converting these cartesian coordinates to a spherical from the centre of the sphere (where the camera will be).
Peter O. is right, of course, although there is an easy standard way to perform an inverse equirectangular projection.
There are two primary ways of writing spherical coordinates, the 'mathematical' and the 'physical'. The only difference is the naming of the coordinates. See the two illustrations of coordinate systems at the top of this article: https://en.wikipedia.org/wiki/Spherical_coordinate_system.
I will assume we use the mathematical one with θ in the x-y-plane and φ in the (x,y)-z-plane. Then, the projection is simply:
θ = 2π * x / w - π, where w is the width of the image and x is the x-position in pixels. This will position midpoints in the image along the x-axis in the sphere, which is probably preferred. If the coordinate system takes value in the [0, 2π]-range, you should do (2π * x / w + π) % 2π instead.
φ = π * y / h, where h is the height of the image, and y is the y-position in pixels.
And r is just some constant which can be freely chosen, of course.
I hope this helps.

Matlab - Discrete values of rho every 10 degrees of object margin in polar coordinates

I have shapes of letters represented in polar coordinates. The centroid of the shape equals the center of the polar representation. I need the values of rho every 10 degrees of the object's outer margin.
Examples of shapes in polar coordinates I have:
I have 2 problems I can't solve:
Matlab's [theta,rho]=cart2pol(x,y) theta doesn't return the angles in degrees. When plotting the object with polar(theta,rho) the object is well represented, but I don't understand what's the equivalence between matlab's theta value and each angle in degrees.
As the margin is in discrete, probably I won't have a margin point for every angle I need, so I need a way to get the nearest margin point for a given angle (and the farthest point for the letters with interior and exterior margin).

Calculate longitude on the 0 degree latitude line, knowing the starting point (latitude,longitude) and azimuth on ellipsoid Earth model

Input:
Observer (Lat,Lon WGS84 coordinates) and an azimuth angle (degrees)
Output:
By considering only the 0 degrees latitude line, I am trying to get the intersection longitude point from the observer point with the given azimuth. I am considering the ellipsoid Earth model.
If you have the Mapping Toolbox available, you can use the track1 function. See the Mathworks documentation at http://www.mathworks.com/help/map/ref/track1.html?refresh=true.
Basic formula is
lon(lat, lon, Z) = lon - atan(sin(lat)*tan(Z))
(Beware that your calculator uses degrees)

How to plot polar with data in matlab like this picture

I have data representing frequency and decibels, and I want to make a polar like this picture:
What is the command for this?
On MathWorks:
The polar function accepts polar coordinates, plots them in a Cartesian plane, and draws the polar grid on the plane.
polar(theta,rho) creates a polar coordinate plot of the angle theta versus the radius rho. theta is the angle from the x-axis to the radius vector specified in radians; rho is the length of the radius vector specified in dataspace units.
You should be able to get your result with polar(decibels, frequency).

Creating a mask with 3 point in Matlab?

I have this 3 points (x,y) and I need to obtain a mask with a triangle where vertices is the points. I should respect some parameters, like the pixel pitch and I need a grid from the minimum x cordinate to the maximum x coordinate (the same for the y).
I tried to do this in matlab with the function poly2mask but the problem is the resultant image: when I have negative coordinates, I cannot see the polygon.
So I tried to center the polygon but I loose the original coordinates and I cannot have they back again because I need to do some elaboration on the image.
How I can obtain a mask triangle from 3 points without modifying the points and respecting the parameters?