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

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).

Related

About imgradient function in Matlab

I am having doubt to the used equation in the function of imgradient.
In the line of 127:
Gdir = atan2(-Gy,Gx)*180/pi; % Radians to degrees
Why the Gy have to be negative?
The y-axis is inverted in images (it increases downward instead of upward). This causes the angles to increase clockwise instead of counter-clockwise as you're used to. By flipping the y component of the gradient, this line computes an angle in the "normal" sense.
Using the graph that #Dan linked in his comment:
In this graph, y increases upward, and angles increase counter-clockwise. In an image, the coordinate system is flipped. This leads to counter-intuitive angles. Hence they invert the y axis to compute the angle.

Onscreen angle of 3D vector

My math is too rusty to figure this out. I want to derive the onscreen angle (the angle as seen on the 2d screen) of a 3d vector.
Given the x and y rotation of a vector (z rotation is zero and doesn't mstter), what does the angle on screen look like?
We know when y is zero and x is positive, the angle is 90. When y is zero and x is negative the angle is -90. When y is 90, for any value of x, the angle is 180. When y is -90, for any value of x, the angle is 0.
So what the formula here so I can derive the angle for the other values of x and y rotation?
The problem, as stated, doesn't make sense. If you're holding z to zero rotation, you've converted a 3D problem to 2D already. Also, it seems the angle you're measuring is from the y-axis which is fine but will change the ultimate formula. Normally, the angle is measured from the x-axis and trigometric functions will assume that. Finally, if using Cartesian coordinates, holding y constant will not keep the angle constant (and from the system you described for x, the angle would be in the range from -90 to 90 - but exclusive of the end points).
The arctangent function mentioned above assumes an angle measured from the x-axis.
Angle can be calculated using the inverse tangent of the y/x ratio. On unity3d coordinated system (left-handed) you can get the angle by,
angle = Mathf.Rad2Deg * Mathf.Atan(y/x);
Your question is what will a 3-d vector look like.
(edit after posted added perspective info)
If you are looking at it isometrically from the z-axis, it would not matter what the z value of the vector is.
(Assuming a starting point of 0,0,0)
1,1,2 looks the same as 1,1,3.
all x,y,z1 looks the same as any x,y,z2 for any values of z1 and z2
You could create the illusion that something is coming "out of the page" by drawing higher values of z bigger. It would not change the angle, but it would be a visual hint of the z value.
Lastly, you can use Dinal24's method. You would apply the same technique twice, once for x/y, and then again with the z.
This page may be helpful: http://www.mathopenref.com/trigprobslantangle.html
Rather than code this up yourself, try to find a library that already does it, like https://processing.org/reference/PVector.html

Calculate angle between 2 geographic coordinates in MATLAB

I'm trying to calculate the angle between 2 geographic (Latitude,Longitude) points in MATLAB. The points are:
(-65.226,125.5) and (-65.236,125.433).
I used the MATLAB function, azimuth, as:
azimuth(-65.226,125.5,-65.236,125.433)
I convert the result to radians, and plotting this using quiver, I get the following plot:
I want the red vector to point from the top right dot to the bottom left dot.
The points are at fairly high latitude (~65S), and the separation of the points is low (about 0.1 degrees). Thus, I can't really understand how the curvature of the earth could affect the azimuth prediction that much..
Does anyone have any experience with azimuth in MATLAB, or have a better suggestion to calculating the angle between the coordinate pairs?
Thanks!
Here you can detailed information and formulae on how to find angle between two latitude-longitude points.

Cylindrical projection to sphere

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.

Quaternions vs Axis + angle

I have been trying to find the difference between the 2 but to no luck minus this
The primary diff erence between
the two representations is that a quaternion’s axis of rotation is scaled
by the sine of the half angle of rotation, and instead of storing the angle in the
fourth component of the vector, we store the cosine of the half angle.
I have no idea what
sine of the half angle of rotation
or
cosine of the half angle
means?
Quaternios and Axis-angle are both 4D representations of 3D rotations/orientations and both have pro's and cons.
Axis-angle: represents the rotation by its angle a and the rotation axis n. For example, a rotation of 180 degrees around the Y-Axis would be represented as a = 180, n= {0,1,0}. The representation is very intuitive, but for actually applying the rotation, another representation is required, such as a quaternion or rotation matrix.
Quaternion: represents a rotation by a 4D vector. Requires more math and is less intuitive, but is a much more powerful representation. Quaternions are easily interpolated (blending) and it is easy to apply them on 3D point. These formula's can easily be found on the web. Given a rotation of a radians about a normalized axis n, the quaternion 4D vector will be {cos a/2, (sin a/2) n_x, (sin a/2) n_y, (sin a/2) n_z}. That's where the sine and cosine of the half angle come from.
It means that if you, for example, want to make a 180deg rotation around the Z axis (0,0,1), then the quaternion's real part will be cos(180deg/2)=0, and its imaginary part will be sin(180deg/2)*(0,0,1)=(0,0,1). That's q=0+0i+0j+1k. 90-degree rotation will give you q=cos(90deg/2)+sin(90deg/2)*(0i+0j+1k)=sqrt(2)/2+0i+0j+sqrt(2)/2*k, and so on.
OTOH, if you're asking what sine and cosine are, check if your languange provides sin() and cos() functions (their arguments will probably be in radians, though), and check out http://en.wikipedia.org/wiki/Sine.