-
-
Notifications
You must be signed in to change notification settings - Fork 0
Mathematical and physical foundations
note:
This is an explanation of homogeneous coordinates defined
in the order w, x, y, z, .... The order is different, but the function is the same...
Since NAS6LIB is not a renderer, there is no right-handed or left-handed system,
and it mainly follows the coordinate system of the renderer.
However, the cross product of vectors is defined in the right-handed system,
and as long as it follows the coordinate system of the renderer, no major problems will occur.
-
Basic property 0: What is an n-dimensional vector V?
- 0-1.V=[V0,V1,...,Vn-1]
It can be written as follows. As will be explained later, in NAS6LIB, V0 is set
as the w (homogeneous) coordinate for homogeneous vectors.
-
Basic property 1:
-
Multiply a vector by a scalar (real number)
-
1-1.aV=Va=[aV0,aV1,...,aVn-1]
-
However, in the case of homogeneous vectors,
the homogeneous coordinates are not multiplied by a, but are written as
-
1-2.aV=Va=[w,aV1,...,aVn-1]
-
Basic property 2:
-
Sum and difference of vectors
-
2-1.P±Q=[P0±Q0,P1±Q1,...,Pn-1±Qn-1]
Let it be
-
-
Basic property 3:
- 3-1.P+Q=Q+P
- 3-2.(P+Q)+R=P+(Q+R)
- 3-3.(ab)P=a(bP)
- 3-4.a(P+Q)=aP+aQ
- 3-5.(a+b)P=aP+bP
-
Basic property 4:
-
Vector sum and difference The vector norm, length, absolute value,
direction cosine, direction cosine, normalized vector, are all almost the same -
4-1.
-
The proof of this is that since length is the shortest distance between two points,
you can find the radius of a circle or sphere,
for example, in two dimensions it becomes the Pythagorean theorem.
Also, a vector with a norm of 1 is called a unit vector,
and changing the norm of a vector to 1 is called normalizing it.
- 4-2.
-
Basic property 5:
- 5-1.|P|≧0
- 5-2.|P|=0←→p=[0,0,...,0]
- 5-3.|aP|=|a||P|
- 5-4.|P+Q|≦|P|+|Q|
-
Basic property 6:
- Vector dot product, dot, scalar product
*6.1
- 6-2.If the angle is θ, then
This can be found from the law of cosines.

Relationship between the angle θ and the dot product of each vector
-
6-3.If the dot product = 0, the vectors are orthogonal.
This can be used to determine whether vectors are orthogonal. -
6-4. If the dot product is > 0, the angle θ is ≦ 90°.
This can be used to determine whether a polygon is front or back. -
6-5. If the dot product is < 0, the angle θ is ≧ 90°.
This can be used to determine whether a polygon is front or back. -
Basic property 7:
For a scalar a and three vectors P, Q, and R- 7-1.P・Q=Q・P
- 7-2.(aP)・Q=a(P・Q)
- 7-3.P・(Q+R)=P・Q+P・R
- 7-4.P・P=|P|^2
- 7-5.|P・Q|≦|P||Q|
-
Basic property 8:

Projection
When projecting vector P onto axis Q, from the diagram- 8-1.
The vertical component is (represented by prep)
- 8-2.
- 8-3. In summary, the three-dimensional transformation matrix for projection is
-
Basic properties 9:
-
Vector cross product, cross, vector product
-
9-1. In the case of three dimensions,
-
The cross product is a vector that is perpendicular to the two vectors being multiplied.
Therefore, it is used to calculate normal vectors, etc.
- 9-2. In summary, the three-dimensional transformation matrix of the cross product is
- 9-3. For any three-dimensional vectors P and Q, (P×Q)・P=0 and (P×Q)・Q=0 hold.
This is because the cross product returns vectors that are perpendicular to each other,
and the perpendicular inner product is 0.
- 9-4.
This can be found from 6-2. by squaring |P×Q|.
Therefore, it is equal to the area of the parallelogram created by them.

Cross product
- Basic property 10:
When the unit vectors x, y, and z are i, j, and k in three dimensions
-
Right-hand rule
- 10-1.i×j=k
- 10-2.j×k=i
- 10-3.k×i=j
- 10-4.j×i=-k
- 10-5.k×j=-i
- 10-6.i×k=-j
-
Left-hand rule
- 10-7.i×j=-k
- 10- 8.j×k=-i
- 10-9.k×i=-j
- 10-10.j×i=k
- 10-11.k×j=i
- 10-12.i×k=j
note:
This is an explanation of homogeneous coordinates defined
in the order w, x, y, z, .... The order is different, but the function is the same...
Since NAS6LIB is not a renderer, there is no right-handed or left-handed system,
and it mainly follows the coordinate system of the renderer.
However, the cross product of vectors is defined in the right-handed system,
and as long as it follows the coordinate system of the renderer, no major problems will occur.
-
Basic properties 11:
- 11-1.P×Q=-(Q×P)
- 11-2.(aP)×Q=a(P×Q)
- 11-3.P×(Q+R)=P×Q+P×R
- 11-4.
- 11-5.(P×Q)・R=(R×P)・Q=(Q×R)・P
- 11-6.
-
Basic property 12:
- Direction cosine, direction cosine, normalized vector
When the angles between the x, y, and z unit vectors and vector P in three dimensions are αβγ, respectively
- 12-1.
This holds the directional information of the vector,
and multiplying it by the length or size will restore the actual original vector.
note:
This is an explanation of homogeneous coordinates defined
in the order w, x, y, z, .... The order is different, but the function is the same...
Since NAS6LIB is not a renderer, there is no right-handed or left-handed system,
and it mainly follows the coordinate system of the renderer.
However, the cross product of vectors is defined in the right-handed system,
and as long as it follows the coordinate system of the renderer, no major problems will occur.
-
Basic property 0:
- 0-1.An i x j matrix M is composed of elements denoted as M_ij,
where i represents the row index and j represents the column index.
- 0-1.An i x j matrix M is composed of elements denoted as M_ij,
The matrix i=j is called a square matrix, the component i=j is called the diagonal component,
and a square matrix with all components except the diagonal component being 0 is called a diagonal matrix.
- 0-2. The transpose of an i x j matrix M, denoted as M.trans(), is a j x i matrix where the rows
and columns are swapped. Each element M_ij in the original matrix becomes M_ji in the transposed matrix.
The standard notation for A$M_{\text{trans()}}$ is M^T
-
Basic property 1:
-
Multiply a matrix by a scalar (real number)
-
1-1.
-
For homogeneous matrices (as described later), the homogeneous coordinate (often M_00 or the last row/column)
is typically not scaled by 'a' during scalar multiplication, maintaining its value for proper homogeneous transformations.
1-2.
Assuming that.
-
Basic property 2:
-
Addition and subtraction of matrices
-
2-1.
-
-
Basic property 3:
-
Multiplication of matrices
For two matrices M (i x m) and N (m x j), their product MN is defined if the number of columns
in M (m) equals the number of rows in N (m).
The element at the i-th row and j-th column of the product MN is calculated as: -
3-1.
-
- 3-2. The identity matrix I is a square matrix for which MI=IM=M holds, and it is
-
Basic property 4:
-
For any scalars a, b and any matrices M, N, O
- 4-1.M+N=N+M
- 4-2.(M+N)+O=M+(N+O)
- 4-3.a(bM)=(ab)M
- 4-4.a(M+N)=aM+aN
- 4-5.(a+b)M=aM+bM
- 4-6.(aM)N=a(MN)
- 4-7.(MN)O=M(NO)
- 4-8.(MN).trans()=N.trans()*M.trans()
-
-
Basic property 5:
- Simultaneous equations
For example, if they are given in the form of
x-y+z=-5
2x+y-3z=19
3x+2y-z=16
If you google "matrix simultaneous equation solution", you can solve it as
Specific solutions include using the inverse matrix and Gaussian elimination.
-
Basic property 6:
-
Inverse matrix
When M^-1 exists such that MM^-1=M^-1M=I, matrix M is called a regular matrix. Matrix M^-1 is called the inverse matrix of matrix M.
Also, a matrix that does not have an inverse matrix is called an irregular matrix. -
6-1. A matrix with only 0 rows or columns is not regular
-
6-2. If matrix M is regular, M.trans() is also regular
-
6-3. If M and N are regular, the product MN is also regular, and (MN)^-1=N^-1M^-1 also holds
-
For how to find the components of an inverse matrix, google "how to find inverse matrix".
Specific solution methods include using cofactor matrices, row elementary transformations, etc.
-
Basic property 7:
- Determinant
The determinant of a square matrix is a scalar quantity obtained from the components,
and is used to determine whether an inverse matrix exists.
- Determinant
To find out how to find a determinant, please Google "How to find a determinant".
-
Basic property 8:
- Eigenvalues, eigenvectors, diagonalization
These are used to diagonalize and simplify matrix calculations.
- Eigenvalues, eigenvectors, diagonalization
To find out how to find eigenvalues, eigenvectors, and diagonalization,
please Google "How to find eigenvalues, eigenvectors, diagonalization".
-
Basic property 9:
- Orthogonal matrix
- 9-1. If a regular square matrix M satisfies M^-1=M.trans(), M is called an orthogonal matrix
- 9-2. If the vector group V0, V1, ..., V(n-1) is orthogonal,
then a matrix using these in order for rows and columns is an orthogonal matrix - 9-3. An orthogonal matrix M preserves length and angle
- Orthogonal matrix
-
Basic property 10:
- Trace of a matrix
- 10-1.
The trace of a square matrix is the sum of the elements on its main diagonal.
For homogeneous matrices, this typically excludes the homogeneous coordinate component
(e.g., the M_00 or M_{n-1,n-1} element depending on convention, if it's not part of
the primary 3x3 or other square sub-matrix for transformation).
-
Basic property 11:
- Scaling transformation
It is as follows.
- 11-1.
-
Basic property 12:
- Rotation transformation around an arbitrary axis
When rotating vector P around the axis of unit vector A,
-
8-1, 8-2 and A on the vector page, part 1 are
$P.proj(A)=(A・P)A$ $P.prep(A)=P-(A・P)A$
Since we want to rotate P.prep(A) by θ, we also need to consider
that the orthogonality of A and P is the cross product
(P-(A・P)A)cosθ+(A×P)sinθ
Add P.proj Add (A)
P'=Pcosθ+(A×P)sinθ+A(A・P)(1-cosθ)
From the above, the rotation transformation around any axis is
- 12-1.
When s=sinθ, c=cosθ, c1=1-c,
This is also the same as the transformation when the norm of |R| is 1 in the rotation vector RV[θ,R0,R1,R2].
This inverse transformation is done by Rodrigues' formula, where m is a 3x3 matrix.
12-2.
tr = m.trace()
if(tr < -1.0) {
m = m/(-tr)
tr = m.trace()
}-
Basic Properties 13:
-
Homogeneous Coordinates
note:
This is an explanation of homogeneous coordinates defined
in the order w, x, y, z, .... The order is different, but the function is the same...
Since NAS6LIB is not a renderer, there is no right-handed or left-handed system,
and it mainly follows the coordinate system of the renderer.
However, the cross product of vectors is defined in the right-handed system,
and as long as it follows the coordinate system of the renderer, no major problems will occur.
When treating a 3D vector as a 3x3 matrix,
it is difficult (or impossible) to preserve the translation component.
So homogeneous coordinates are created by adding a dimension w for concise representation.
13-1. Given a matrix M, a vector P, and a translation vector T (which of course are not homogeneous),
the homogeneous coordinate transformation F is given as follows:
Since we want to convert in the format P'=MP+T, and in the general mathematical conventions,
And if we multiply R=[Rx,Ry,Rz,1] from the back of F,
It is converted as follows.
The same thing can be said if you multiply F by a matrix similar to F, but we will not explain it here.
If R'w is not 1, that is, F33 is not 1,
you can normalize and get the correct result by dividing the whole by (F33 = Fw) or Rw.
And here we will explain the implementation of NAS6LIB.
We want to convert in the format Q'=MQ+T, so
And if we multiply S=[1,Sx,Sy,Sz] from the back of G,
This format is the same as the general mathematical convention format mentioned earlier,
so it is converted correctly without any major problems.
Mij is the rotational transformation component.
Tk is the translational component.
Row N0 is the w component row.
Row N1 is the row for the x-axis component of the rotation matrix (local coordinate system).
Row N2 is the row for the y-axis component of the rotation matrix (local coordinate system).
Row N3 is the row for the z-axis component of the rotation matrix (local coordinate system).
note:
Vector × matrix calculations are column-major calculations
Matrix × vector calculations are row-major calculations
The advantage of the row-major calculation format used by NAS6LIB
is that each axis of the local rotation transformation can be extracted straightforwardly as a row
The translation components in this case are arranged in columns
But by multiplying them with a homogeneous zero vector,
they can also be extracted straightforwardly
In this case, the row-major notation for the formula is mainly N6LMatrix.Mul(N6LVector),
but it is also possible to write it as column-major notation
N6LVector.Mul(N6LMatrix) depending on the situation.
13-2. Any homogeneous vector S or homogeneous matrix G can be standardized
by dividing the whole by (S0 = Sw) and (G00 = Gw), that is, by dividing by the "w element" (1 in 13-1).
-
Basic property 14:
- Rotation vector
This is closely related to quaternions, which will be described later.
Homogeneous coordinates (4x4) can be stored as four elements:
the rotation axis vector (3) and the rotation angle.
The rotation vector is the result of this, based on basic property 12.
As mentioned in 12-2,
the inverse transformation of a rotation matrix is given by Rodrigues' formula, where m is a 3x3 matrix.
- 12-2.
tr = m.trace()
if(tr < -1.0) {
m = m/(-tr)
tr = m.trace()
}If R results in a zero vector (indicating a rotation angle of 0 or π radians, or multiple axes for 180-degree rotation),
the rotation vector alone may not uniquely determine the axis. In such cases, converting the rotation matrix to
a quaternion might provide a more robust method to find the rotation axis and angle.
The following is how to convert a rotation vector to a rotation matrix
12-1.
When s=sinθ,c=cosθ,c1=1-c
note:
This is an explanation of homogeneous coordinates defined
in the order w, x, y, z, .... The order is different, but the function is the same...
Since NAS6LIB is not a renderer, there is no right-handed or left-handed system,
and it mainly follows the coordinate system of the renderer.
However, the cross product of vectors is defined in the right-handed system,
and as long as it follows the coordinate system of the renderer, no major problems will occur.
Quaternion are introduced as rotations around arbitrary axes.
This is because it reduces memory capacity and the number of calculations.
-
Basic property 0: What is a quaternion Q?
- 0-1.Q=[w,x,y,z]=w+xi+yj+zk=s+v
It can be written as follows. i,j,k are the imaginary units of each axis,
s is w, and v is the [x,y,z] vector.
The properties of the imaginary unit are
-
0-2.i^2=j^2=k^2=-1
-
0-3.ij=-ji=k
-
0-4.jk=-kj=i
-
0-5.ki=-ik=j
-
Basic property 1:
- Product of quaternions
When q1=[w1,x1,y1,z1],q2=[w2,x2,y2,z2]
- 1-1.
When q1=[s1,v1],q2=[s2,v2]
-
1- 2.q1q2=s1s2-v1・v2+s1v2+s2v1+v1×v2
-
Basic property 2:
-
Conjugate
-
2-1.When q=[s,v] is given, q~=[s,-v] is called the conjugate
-
2-2.qq~=q~q=q・q=|q|^2=q^2 is the square of the magnitude
-
-
Basic property 3:
-
Inverse
-
3-1.The inverse q^-1=q~/q^2
-
-
Basic property 4:
-
Rotation
-
4-1.For a vector P and a quaternion q, P.rot(q)=qPq^-1.
-
If q=[s,v] is the unit quaternion, then q^-1=[s,-v], and
- 4-2.
Here, if v=tA as unit vector A, then
4-3.qPq^-1=(s^2-t^2)P+2st(A×P)+2t^2(A・P)A
Compared to matrix rotation,
t =√((1-cosθ)/2)=sin(θ/2), and from s^2+t^2=1, s=cos(θ/2)
4-4. Quaternion of angle θ around axis A q=cos(θ/2)+Asin(θ/2)
4-5. In summary, the conversion of quaternions is
This inverse transformation is done with homogeneous matrix m
4-6.
QSIGN = function(x) {
if(0.0 <= x) return 1.0
return -1.0
}
ret = [( m11 + m22 + m33 + 1.0) / 4.0, ( m.x11 - m22 - m33 + 1.0) / 4.0,
(-m11 + m22 - m33 + 1.0) / 4.0, (-m11 - m22 + m33 + 1.0) / 4.0)]
if(ret0 < 0) ret0 = 0
if(ret1 < 0) ret1 = 0
if(ret2 < 0) ret2 = 0
if(ret3 < 0) ret3 = 0
ret0 = √(ret0)
ret1 = √(ret1)
ret2 = √(ret2)
ret3 = √(ret3)
r = ret0
if(r < ret1) r = ret1
if(r < ret2) r = ret2
if(r < ret3) r = ret3
if(r == ret0) {
ret0 *= 1
ret1 *= QSIGN(m32 - m23)
ret2 *= QSIGN(m13 - m31)
ret3 *= QSIGN(m21 - m12)
}
else if(r == ret.q.x[1]) {
ret0 *= QSIGN(m32 - m23)
ret1 *= 1
ret2 *= QSIGN(m21 + m12)
ret3 *= QSIGN(m13 + m31)
}
else if(r == ret.q.x[2]) {
ret0 *= QSIGN(m13 - m31)
ret1 *= QSIGN(m21 + m12)
ret2 *= 1
ret3 *= QSIGN(m32 + m23)
}
else {
ret0 *= QSIGN(m21 - m12)
ret1 *= QSIGN(m13 + m31)
ret2 *= QSIGN(m32 + m23)
ret3 *= 1
}
return retIt is.
- 4-7.
Calculate rotation axis and rotation angle from quaternion
The rotation angle θ can be calculated as
θ=2 * cos^-1(q.w)
and the rotation axis R can be calculated as
R=[q.x/sin(θ/2), q.y/sin(θ/2), q.z/sin(θ/2)]
When θ=0, the rotation axis cannot be calculated from it, so
calculate the rotation matrix from the quaternion:
R=[m32-m23, m13-m31, m21-m12]
If this is a zero vector
R=[m32, m13, m21]
If this is a zero vector
R=[m11, m22, m33]
- 4-8.
To perform rotation operations with a rotation vector,
quaternion operations can be used as is.
When the rotation vector is θ,
the quaternion is expressed as q=cos(θ/2)+Asin(θ/2)
from 4-4., and the rotation operation can be performed
with that quaternion without using a matrix.
For 3D rotation, if you have a rotation vector, you can get a quaternion
from it and rotate it, so the only place matrices are used is translation.
I wonder if it's possible to create a quaternion that also includes translation.
I think it will probably be an octonion of θ, 3D axis, homogeneous W, and 3D point.
If this can be done, it will be 4x4 homogeneous coordinates. Matrices will probably become obsolete
It was easier than I thought
- 4-9.
The attitude vector P is defined as follows
When homogeneous translation T and quaternion Q are used
P = [T, Q]
Also, this product is
When P1 = [T1, Q1] and P2 = [T2, Q2]
P1P2 = [T1 + Q1T2Q1^-1, Q1Q2]
This should make it easier to calculate without expressing it as a homogeneous coordinate matrix
- Confirmation calculation
The above works fine when compared to the matrix, so it should be correct
The speed is calculated by counting the number of product terms
The matrix product is 16^2=256
The attitude vector product is
P1P2=[T1+Q1T2Q1^-1, Q1Q2]
Q1T2Q1^-1
and the (quaternion → matrix) vector
is added to T1's vector and multiplied by Q1Q2's quaternion, so the calculation is
It's 18 x 3 + 4^2 = 70, but I don't know if it's really that fast.
The capacity is 16 matrices and 8 orientation vectors (7 if homogeneous information is shaped).
Summary: Three dimensions can be completely described with 7 parameters: ternary translation T + quaternion Q.
This is defined as the orientation vector P. P = [1, T, Q]
The product of P1 and P2, that is, the rotation, is written as P1P2 = [T1 + Q1T2Q1^-1, Q1Q2].
The speed is calculated by counting the number of product terms, and the matrix product is 16^2 = 256,
and the attitude vector product is P1P2 = [T1 + Q1T2Q1^-1 ○ Q1Q2], and Q1T2Q1^-1 (quaternion → matrix) vector.
Add T1 to the vector and multiply it by the quaternion of Q1Q2, and the result is 18 x 3 + 4^2 = 70.
-
Basic property 5:
-
Linear interpolation
-
5-1.0≦t≦1, initial q1, end q2
-
q.lerp(t)=(1-t)q1+tq2
-
Basic property 6:
-
Spherical linear interpolation
-
6-1.s=sinθ=√(1-(q1・q2)^2), 0≦t≦1, initial q1, end q2
-
q.slerp(t)=(s(1-t)/s)q1+(st/s)q2
What are quaternions and quaternions essentially?
Orthogonal and imaginary axis relationships
First, look at Geometric Interpretation of Imaginary Units and Rotations
The inversion axis is X^2=-I
The orthogonal axis is X=iI
If we consider quaternions with this understanding
This means that the parameters wxyz are mutually orthogonal
Therefore, it has a high affinity with the Euclidean system
It can be used for rotation transformations in the Euclidean system
What are quaternions and quaternions essentially? The relationships between orthogonal and imaginary axes.
First, refer to the understanding of axial orthogonality and imaginary axis relationships.
The "inversion axis" (
(Note: These terms "inversion axis" and "orthogonal axis" as used here are non-standard in a typical mathematical context.
If they are specific to NAS6LIB's internal definitions, please clarify. Generally, i^2 = -1 defines the imaginary unit,
and its geometric interpretation in rotations is through complex numbers or quaternions.)
If we consider quaternions with this understanding, it means that the parameters
Therefore, it has a high affinity with the Euclidean system, making it suitable for rotation transformations in the Euclidean system.
Graph as a rotation transformation of the complex plane
It is convenient to use imaginary numbers for axis orthogonality.
For 2D, the relationship
Here,
(Note: In 2D, only one imaginary unit is typically used (e.g., i for the complex plane).
The expression seems to involve two imaginary units for a 2D context, which might be confusing.)
Why do we do it like this?
The rotation matrix
The product of two rotation matrices
Calculating this product gives:
From the angle addition formulas:
So if
In other words, for a
This implies that the imaginary axis rotates
The 2D relationship
(Note: Re-evaluate this equation's relevance and clarity in the context of 2D complex numbers vs. 3D quaternions. In 2D complex numbers,
A
This means the orthogonal axis can be viewed as an imaginary axis (
When rotated by
Also, the orthogonality of axes is related to the dot product.
For example, in the case of a rotation of the x-axis around the y-axis:
A
A
This directly relates to the definition of the dot product itself.
In short, if you multiply the axis by an imaginary unit to make it an imaginary axis, the axes are
in an orthogonal relationship. Also, since it is an imaginary axis, two
in a
- Digression
The definition of
Fourier Transform, and properties of trigonometric functions, circles, etc.
You can just calculate
using a regular calculator. The use of 360 degrees (
(Earth's year being 365.2425 days) for celestial sphere rotation (approx. 1 degree per day)
is a historical convention due to 360 being a natural number with many divisors.
The concept of "positive world" (in front), "negative world" (behind), and "imaginary world"
(to the side) provides a conceptual analogy. Strictly speaking, up/down are also distinct,
but using a mirror in front of you as an analogy to visualize the "negative world" behind you can be helpful.
In this section, we expand on the concepts introduced in the previous section,
"The Geometric Interpretation of Imaginary Units and Rotations,"
by providing a detailed description of the main operations on vectors in 3D space:
dot and cross products, and how they relate to orthogonality and rotation axes.
- Dot product
The dot product (also called scalar product) of two vectors is important and often used in 3D graphics
This shows the difference in the direction of the vectors,
and also the extent to which one vector "aligns" (projects) with respect to the other.
- Vector dot product, dot, scalar product
*6.1
This further becomes when
It satisfies and can be written as the product of

Relationship between the angle θ and the dot product of each vector
- Cross product
The cross product (also called vector product) of two three-dimensional vectors returns
the normal vector of the plane in which the two vectors exist
Therefore, the direction has a front and a back, and this determines whether it is a left-handed or right-handed system
-
Vector cross product, cross, vector product
-
9-1. In the case of three dimensions,
Therefore
and the magnitude of the cross product is
Therefore, the cross product of a vector returns the normal of the plane in the left-handed or right-handed system.

Cross product
Back to Table of contents
Back to NAS6LIB Repository [Links outside the wiki]