Healpy and the 4D Sphere - how to use pix2ang to create the 3 arrays of angles (ksi, theta, phi)? - healpy

I am working with hyperspheres and would like to use healpy to create the three angles
ksi, theta, phi for a nside hypersphere.
How do I do that considering that these are the four coordinates of this hypersphere:
u1=sin(ksi)sin(theta)cos(phi)
u2=sin(ksi)sin(theta)sin(phi)
u3=sin(ksi)cos(theta)
u4=cos(ksi)
Thanks,
Marco

Related

Fitting of a sphere using SVD/LMS

I would like to fit a MR binary data of 281*398*104 matrix which is not a perfect sphere, and find out the center and radius of sphere and error also. I know LMS or SVD is a good choice to fit for sphere.
I have tried sphereFit from matlab file exchange but got an error,
>> sphereFit(data)
Warning: Matrix is singular to working precision.
> In sphereFit at 33
ans =
NaN NaN NaN
Would you let me know where is the problem, or any others solution?
If you want to use sphere fitting algorithm you should first extract the boundary points of the object you assume to be a sphere. The result should be represented by a N-by-3 array containing coordinates of the points. Then you can apply sphereFit function.
In order to obtain boundary point of a binary object, there are several methods. One method is to apply morphological erosion (you need the "imerode" function from the image processing toolbox) with small structuring element, then compute set difference between the two images, and finally use the "find" function to transform binary image into a coordinate array.
the idea is as follow:
dataIn = imerode(data, ones([3 3 3]));
bnd = data & ~data2;
inds = find(bnd);
[y, x, z] = ind2sub(size(data), inds); % be careful about x y order
points = [x y z];
sphere = sphereFitting(points);
By the way, the link you gave refers to circle fitting, I suppose you wanted to point to a sphere fitting submission?
regards,

3D Ellipsoid out of discrete units

I'm trying to draw an ellipsoid in 3d space out of individual blocks.
I have no problem with 2D ellipses, but as far as 3D goes I'm having some trouble. I'm using Bresenham's circle algorithm to draw 2D ellipses. What I'm trying to do is draw 2D ellipses in layers with an increasing (starting from the bottom going up, using symmetry for the other half) radius on both the X radius and Y radius.
It all sounds like it would work, but when I go to implement it, I can't figure out how to alter the x radius and y radius to make the curve of the ellipsoid.
Your 2D slices should all have the same orientation and aspect ratio.
If your ellipsoid is axis-aligned, they should also have the same center.
Your slices should scale proportionally to:
scale = sqrt(1 - ((center-z)/half_vsize)^2)
where:
z = height of the current slice
center = height of the largest slice
half_vsize = half the vertical size of the ellipsoid
If (x0, y0) is the x- and y-width of the largest slice, (x, y) = (scale*x0, scale*y0) is the x- and y-width of the slice at height z.

Convert OpenGL 4x4 matrix to rotation angles

I am extracting in OpenGL the Model Matrix with
glGetFloatv (GL_MODELVIEW_MATRIX, (float*)x)
And would like to extract from the resulting 4x4 matrix the x,y and z axis rotations. How Can I do that ?
Thanks !
First you should know, that x,y,z axis rotations, called Euler Angles suffer from serious numerical problems. Also they're not unambigous. So either you store a rotation angle and the rotation axis, thus effectively forming a quaternion in disguise, or you stick with the full rotation matrix.
Find the quaternion from a rotation matrix is called an eigenvalue problem. Technically you're determining the eigenvector of the rotation matrix, which is the axis and the magnitude designates the angle.
I'm writing a CAD-like app, so I understand your problem, we 'in the business' know how awful Euler angles are for linear transformations - but the end-user finds them far more intuitive than matrices or quaternions.
For my app I interpreted Ken Shoemake's wonderful algorithm, it's one of the very few that support arbitrary rotation orders. It's from '93, so it's in pure C code - not for the faint hearted!
http://tog.acm.org/resources/GraphicsGems/gemsiv/euler_angle/
Something like this should give you what you're after.
final double roll = Math.atan2(2 * (quat.getW() * quat.getX() + quat.getY() * quat.getZ()),
1 - 2 * (quat.getX() * quat.getX() + quat.getY() * quat.getY()));
final double pitch = Math.asin(2 * (quat.getW() * quat.getY() - quat.getZ() * quat.getY()));
final double yaw = Math.atan2(2 * (quat.getW() * quat.getZ() + quat.getX() * quat.getY()), 1 - 2 * (quat.getY()
* quat.getY() + quat.getZ() * quat.getZ()));
I use this as a utility function to print out camera angles when I'm using SLERP to interpolate between 2 quaternions that I've derived from 2 4x4 matrices (i.e. camera movement between 2 3D points).

Angle from vector

Say I have point A (20,20) and point B (60,60).
The resulting vector would be 40, 40. How could I get the angle of this vector?
By this I mean, imagine there is an imaginary circle around the origin.
I guess sort of what atan2 does but without atan2.
Thank
Presuming that you want to find the angle of the vector against the X axis (in JavaScript):
var vector = {x: 40, y: 40};
var rad = Math.atan(vector.y/vector.x)
var deg = rad * 180/Math.PI;
alert(deg); // 45 deg
I'm not sure what you mean by angle, since you only give one vector in your example. But, given two vectors, you can find the angle between them like so:
Given vectors a and b, normalize both of them. Then, dot(a, b) = cos(θ), where θ is the angle between the two vectors. Use arccos to find θ.
Below is the link that will show you how to find the angle bewteen two vectors:
http://www.wikihow.com/Find-the-Angle-Between-Two-Vectors

Converting Cartesian 5D and Angular 2D to Lat Long Alt

Does anyone has the formula to convert X,Y,Z,Vx,Vy(cartesian 5D) as well as Azimuth, Elevation(Angular 2D) to Lat Long Alt? Thanks.
You do not make clear what you mean by "cartesian 5D" (I suppose vx and vy are velocities in some plane?), but for a 3D system (x, y, z) you are looking for the conversion to polar coordinates (r, θ, φ).
If by "altitude" you mean the height over some sphere of radius R, you can easily get it from the r coordinate h=r-R.

Resources