Estimate Quaternion from the Full Transformation matrix(4x4) with shear - math

I have obtained a full transformation matrix (4x4) (the s form) and looks like this
array([[-4.10156250e-01, 0.00000000e+00, 0.00000000e+00, 8.90400009e+01],
[ 0.00000000e+00, 4.11722958e-01, -7.76345863e-02, -1.59686249e+02],
[ 0.00000000e+00, 3.57474685e-02, 8.93157482e-01, -2.27202545e+02],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00]])
The operations encoded in the transformation matrix are rotation, translation, scaling, and shear. I want to calculate the proper 3x3 rotation matrix so that I can estimate the quaternions for the above matrix.

Take a look at how this is done in BRAINSTools.

Related

Bend a mesh along spline

I am trying to bend a mesh along a spline curve and currently out of ideas … at first I thought I just add spline point vectors to mesh's vertices , but I am looking for more optimized version of it …
so guys …
How can I bend a mesh along a spline, so that mesh, with some forward axis vector follows the spline and bends according to it and also repeat along the spline …
???
I believe there are many ways to do what you want. Some years ago I worked out an approach using Conformal Geometric Algebra. Of course you can do it using conventional 3D math as its described in Instant Mesh Deformation and Deformation styles for spline-based skeletal animation papers.
A simple method is as follows:
Your spline function is a function S(t): R -> R^3, it takes a scalar between [0:1] and give you points in R^3.
Project each mesh vertex on the spline curve. The projection is orthogonal in the sense that it follows the direction of a normal vector to the curve. So your mesh vertex v_i is projected to a point v'_i in the spline where S(t_i) = v'_i. Form a vector p_i = v_i - v'_i (which is normal to the curve) so each mesh vertex can be expressed as:
v_i = S(t_i) + p_i
Compute an orthogonal coordinate system at "each point" of the spline. That coordinate system is known as Frenet-Serret frame. The first vector to determine is the tangent to the curve. It is uniquely defined as the derivative of S(t) so tangent T = S(t)/dt. The other two vectors, the normal N and binormal B, can be computed in different ways, check the above reference papers for that.
Express the vector p_i (from step 1) in terms of the Frenet-Serret frame at point S(t_i). Such that the vector p_i is a linear combination of T, N and B. Create a matrix A with columns T, N and B. You need to find x_i such that:
A x_i = p_i
That can be solved by inverting the matrix A (actually taking the transpose should suffice). So each mesh vertex can be computed as:
v_i = S(t_i) + A x_i
You can store the pair (t_i, x_i) instead of v_i (you don't need to store v_i anymore since you can compute it from t_i and x_i).
To deform the mesh deformation the spline control points must be translated, then you need to recompute the Frenet-Serret frame of each spline point (taking the derivative of the S(t) to compute T and updating the N and B as suggested in above reference papers). Once you have the updated T, N and B, you can define the matrix A and then compute the mesh vertex positions using formula from step 3.
Results can be seen in pictures of the above mentioned papers.

rotational matrix in R

I want to achieve an algorithm in R. I cannot start with the code because I am having problem figuring out the problem clearly. The problem is related to rotational matrix, which is actully pretty challenging.
The problem is as follow:
The historical data of monthly flows X is transformed into Y by the transformation matrix R where,
Y = RX (3)
The procedure for obtaining the transformation matrix is described in detail in the appendix of Tarboton et al. (1998), here we summarize from their description. The transformation matrix is developed from a standard basis (basis vectors aligned with the coordinate axes) which is orthonormal but does not have a basis vector perpendicular to the conditioning plane defined by (3). One of the standard basis vectors is replaced by a vector perpendicular to the conditioning plane. Operationally this amounts to starting with an identity matrix and replacing the last column with . Clearly the basis set in no longer orthonormal. Gram Schmidt orthonormalization procedure is applied to the remaining 1 standard basis vectors to obtain an orthonormal basis that now includes a vector perpendicular to the conditioning plane.
The last column of the matrix Y, , and the R matrix has the property
RT = R^(-1). The first components of the vector can be denoted as as the last component is , i.e., . Hence, the simulation involves re-sampling from the conditional PDF ( )

Estimate the angles of orientation (alpha,beta and gamma) by camera calibration

I'm trying to estimate the three angles of orientation by camera calibration. I'm using matlab toolbox for calibration process.
Matlab camera calibration Toolbox process return the Rotation vector:
omc_ext = [ 2.181316 2.182162 -0.076635 ]
and Rotation matrix:
Rc_ext = [
-0.000242 0.999992 0.003935
0.997253 0.000533 -0.074075
-0.074076 0.003906 -0.997245 ]
How it possible to estimate the three angles of orientation from the above information ?
The three angles you are looking for are called Euler angles and they are not unique unless you have more information about the order in which the rotations are performed. Usually it's best to just work with the 3x3 rotation matrix unless you have some special need to know the angles.
Mathworld lists the trig equations necessary to calculate the Euler angles from the rotation matrix.
http://mathworld.wolfram.com/EulerAngles.html

Normalizing a matrix with respect to a constraint

I am doing a project which requires me to normalize a sparse NxNmatrix. I read somewhere that we can normalize a matrix so that its eigen values lie between [-1,1] by multiplying it with a diagonal matrix D such that N = D^{-1/2}*A*D^{-1/2}.
But I am not sure what D is here. Also, is there a function in Matlab that can do this normalization for sparse matrices?
It's possible that I am misunderstanding your question, but as it reads it makes no sense to me.
A matrix is just a representation of a linear transformation. Given that a matrix A corresponds to a linear transformation T, any matrix of the form B^{-1} A B (called the conjugate of A by B) for an invertible matrix B corresponds to the same transformation, represented in a difference basis. In particular, the eigen values of a matrix correspond to the eigen values of the linear transformation, so conjugating by an invertible matrix cannot change the eigen values.
It's possible that you meant that you want to scale the eigen vectors so that each has unit length. This is a common thing to do since then the eigen values tell you how far a vector of unit length is magnified by the transformation.

Split a transform matrix into orhhogonal matrix and scale matrix

If I have a matrix from scale, translate, and rotation transform. I want to split this matrix to two matrix. One is rotation+translation matrix, the other is scale matrix.
Because I want to compute the correct normal vector transform, so I only need orthogonal matrix to do the computation for surface normal vector
Any ideas?
If I have a matrix from scale, translate, and rotation transform. I want to split this matrix to two matrix. One is rotation+translation matrix, the other is scale matrix.
I'm assuming this matrix you are talking about is a 4x4 matrix that is widely used by some, widely despised by others, with the fourth row being 0,0,0,1.
I'll cause these two operations "scale" and "rotate+translate". Note well: These operations are not commutative. Scaling a 3-vector and then rotating/translating this scaled vector yields a different result than you would get by reversing the order of operations.
Case 1, operation is "rotate+translate", then "scale".
Let SR=S*R, where S is a 3x3 diagonal matrix with positive diagonal elements (a scaling matrix) and R is a 3x3 orthonormal rotation matrix. The rows of matrix SR will be orthogonal to one another, but the columns will not be orthogonal. The scale factors are the square root of the norms of the rows of the matrix SR.
Algorithm:
Given 4x4 matrix A, produce 4x4 scaling matrix S, 4x4 rotation+translation matrix T
A = [ SR(3x3) Sx(3x1) ]
[ 0(1x3) 1 ]
Partition A into a 3x3 matrix SR and a 3 vector Sx as depicted above.
Construct the scaling matrix S. The first three diagonal elements are the vector norms of the rows of matrix SR; the last diagonal element is 1.
Construct the 4x4 rotation+translation matrix T by dividing each row of A by the corresponding scale factor.
Case 2, operation is "scale", then "rotate+translate".
Now consider the case RS=R*S. Here the columns of A will be orthogonal to one another, but the rows will not be orthogonal. In this case the scale factors are the square root of the norms of the columns of the matrix RS.
Algorithm:
Given 4x4 matrix A, produce 4x4 rotation+translation matrix T, 4x4 scaling matrix S
A = [ RS(3x3) x(3x1) ]
[ 0(1x3) 1 ]
Partition A into a 3x3 matrix RS and a 3 vector x as depicted above.
Construct the scaling matrix S. The first three diagonal elements are the vector norms of the columns of matrix RS; the last diagonal element is 1.
Construct the 4x4 rotation+translation matrix T by dividing each row of A by the corresponding scale factor.
If the scaling is not uniform (e.g., scale x by 2, y by 4, z by 1/2), you can tell the order of operations by looking at the inner products of the rows and columns of the upper 3x3 matrix with one another. Scaling last (my case 1) means the row inner products will be very close to zero but the column inner products will be non zero. Scaling first (my case 2) reverses the situation. If the scaling is uniform there is no way to tell which case is which. You need to know beforehand.
Just an idea -
Multiply the matrix by the unit vectors (1/sqrt(3),1/sqrt(3),1/sqrt(3)),
check how the length of the vector after the multiplication,
scale the matrix by the reciprocal of that value. Now you have an orthogonal matrix
create a new scale matrix with the scale you found.
Remove the translation to get a 3x3 matrix
Perform the polar decomposition via SVD.

Resources