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
Related
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.
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.
I have nxn matrix in 2D space; I would like to rotate the matrix around the x-axis using matlab. Where the x-axis pass through the center of the matrix (pass through the point [n/2 n/2].
I found the Matlab function B = rot90(A) which rotate the matrix A by 90 degree. But I’m looking for a method that rotate matrix A by any given angle (e.g. 30, 45, 170 degree) around the x-axis.
You can as well try imrotate(). This function is from the Image Processing Toolbox, but since its main input is a matrix (either real or logical) it'll work also for non picture-related matrices (I've tried with a magic matrix).
The syntax is:
B=imrotate(A,theta);
where A is you matrix, B is the rotated version of A and theta is the rotation in degrees. The rotation is performed in counterclockwise direction around its center point; to rotate the matrix clockwise, specify a negative value for theta.
These things are not clear.
What are the units of
1.Data given by (CMGyroData) basically x,y and z?
What is the minimum and maximum variation of one axis data(For eg, x axis)
Does this x data represent the rotation(or swing) around the x axis?
The place to look is the documentation: http://developer.apple.com/library/ios/#documentation/CoreMotion/Reference/CMGyroData_Class/Reference/Reference.html.
x
The X-axis rotation rate in radians per second. The sign follows the
right hand rule: If the right hand is wrapped around the X axis such
that the tip of the thumb points toward positive X, a positive
rotation is one toward the tips of the other four fingers.
etc.
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.