UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MatrixH.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "Core/Types.h"
5#include "Math/MathConst.h"
6#include "Math/Point.h"
7
8namespace UE::CADKernel
9{
14{
15private:
16 double Matrix[16];
17
18public:
19
20 static const FMatrixH Identity;
21
23 {
24 SetIdentity();
25 }
26
27 FMatrixH(const double* const InMatrix16)
28 {
29 for (int32 Index = 0; Index < 16; Index++)
30 {
32 }
33 }
34
35 FMatrixH(const double InMatrix44[][4])
36 {
37 for (int32 Row = 0; Row < 4; Row++)
38 {
39 for (int32 Column = 0; Column < 4; Column++)
40 {
41 Matrix[4 * Row + Column] = InMatrix44[Row][Column];
42 }
43 }
44 }
45
46 FMatrixH(const FVector& Origin, const FVector& Ox, const FVector& Oy, const FVector& Oz)
47 {
48 BuildChangeOfCoordinateSystemMatrix(Ox, Oy, Oz, Origin);
49 }
50
52 {
53 Ar.Serialize(InMatrix.Matrix, 16 * sizeof(double));
54 return Ar;
55 }
56
58 {
59 for (int32 Row = 0; Row < 4; Row++)
60 {
61 for (int32 Column = 0; Column < 4; Column++)
62 {
63 Get(Row, Column) = Row == Column ? 1. : 0.;
64 }
65 }
66 }
67
68 void FromAxisOrigin(const FVector& Axis, const FVector& Origin);
69
77 void BuildChangeOfCoordinateSystemMatrix(const FVector& Xaxis, const FVector& Yaxis, const FVector& Zaxis, const FVector& Origin);
78
80 {
81 return FVector(
82 InPoint.X * Get(0, 0) + InPoint.Y * Get(0, 1) + InPoint.Z * Get(0, 2) + Get(0, 3),
83 InPoint.X * Get(1, 0) + InPoint.Y * Get(1, 1) + InPoint.Z * Get(1, 2) + Get(1, 3),
84 InPoint.X * Get(2, 0) + InPoint.Y * Get(2, 1) + InPoint.Z * Get(2, 2) + Get(2, 3)
85 );
86 }
87
88 FVector Multiply(const FVector2d& Point2D) const
89 {
90 return Multiply(FVector(Point2D, 0.));
91 }
92
93 FVector2d Multiply2D(const FVector2d& Point2D) const
94 {
95 const FVector Point = Multiply(FVector(Point2D, 0.));
96 return FVector2d(Point.X, Point.Y);
97 }
98
99 FVector MultiplyVector(const FVector& InVector) const
100 {
101 return FVector(
102 InVector.X * Get(0, 0) + InVector.Y * Get(0, 1) + InVector.Z * Get(0, 2),
103 InVector.X * Get(1, 0) + InVector.Y * Get(1, 1) + InVector.Z * Get(1, 2),
104 InVector.X * Get(2, 0) + InVector.Y * Get(2, 1) + InVector.Z * Get(2, 2)
105 );
106 }
107
108 FVector MultiplyVector(const FVector2d& Point2D) const
109 {
110 return MultiplyVector(FVector(Point2D, 0.));
111 }
112
114 {
115 const FVector Point = MultiplyVector(FVector(Point2D, 0.));
116 return FVector2d(Point.X, Point.Y);
117 }
118
119 FVector3f MultiplyVector(const FVector3f& InVector) const
120 {
121 return FVector3f(
122 (float)(InVector.X * Get(0, 0) + InVector.Y * Get(0, 1) + InVector.Z * Get(0, 2)),
123 (float)(InVector.X * Get(1, 0) + InVector.Y * Get(1, 1) + InVector.Z * Get(1, 2)),
124 (float)(InVector.X * Get(2, 0) + InVector.Y * Get(2, 1) + InVector.Z * Get(2, 2))
125 );
126 }
127
128 static FMatrixH MakeRotationMatrix(double InAngle, const FVector InAxe);
129
130 static FMatrixH MakeTranslationMatrix(const FVector& InPoint);
131
132 static FMatrixH MakeScaleMatrix(FVector& Scale);
133 static FMatrixH MakeScaleMatrix(double ScaleX, double ScaleY, double ScaleZ);
134
138 FVector PointRotation(const FVector& PointToRotate, const FVector& Origin) const
139 {
140 FVector Result = Origin;
141 for (int32 Index = 0; Index < 3; Index++)
142 {
143 for (int32 Jndex = 0; Jndex < 3; Jndex++)
144 {
145 Result[Index] += Get(Index, Jndex) * (PointToRotate[Jndex] - Origin[Jndex]);
146 }
147 }
148 return Result;
149 }
150
152 {
153 FVector2d Result = Origin;
154 for (int32 Index = 0; Index < 2; Index++)
155 {
156 for (int32 Jndex = 0; Jndex < 2; Jndex++)
157 {
158 Result[Index] += Get(Index, Jndex) * (PointToRotate[Jndex] - Origin[Jndex]);
159 }
160 }
161 return Result;
162 }
163
164 void Inverse();
165
167 {
168 FMatrixH NewMatrix = *this;
170 return NewMatrix;
171 }
172
174 {
175 FMatrixH Tmp = *this;
176 for (int32 Index = 0; Index < 4; Index++)
177 {
178 for (int32 Jndex = 0; Jndex < 4; Jndex++)
179 {
180 Get(Index, Jndex) = Tmp.Get(Jndex, Index);
181 }
182 }
183 }
184
185 double& Get(int32 Row, int32 Column)
186 {
187 return Matrix[Row * 4 + Column];
188 }
189
190 double Get(int32 Row, int32 Column) const
191 {
192 return Matrix[Row * 4 + Column];
193 }
194
195 double& operator()(int32 Row, int32 Column)
196 {
197 return Matrix[Row * 4 + Column];
198 }
199
200 double operator()(int32 Row, int32 Column) const
201 {
202 return Matrix[Row * 4 + Column];
203 }
204
206 {
207 return Matrix[Index];
208 }
209
211 {
212 FMatrixH Result;
213
214 for (int32 Index = 0; Index < 4; Index++)
215 {
216 for (int32 Jndex = 0; Jndex < 4; Jndex++)
217 {
218 Result.Get(Index, Jndex) = 0;
219 for (int32 Kndex = 0; Kndex < 4; Kndex++)
220 {
221 Result.Get(Index, Jndex) = Result.Get(Index, Jndex) + (Get(Index, Kndex) * InMatrix.Get(Kndex, Jndex));
222 }
223 }
224 }
225 return Result;
226 }
227
229 {
230 FMatrixH Result = *this * InMatrix;
231 Move(*this, Result);
232 }
233
235 {
236 return Multiply(Point);
237 }
238
240 {
241 FMatrixH Result;
242 for (int32 i = 0; i < 16; i++)
243 {
244 Result.Matrix[i] = Matrix[i] + InMatrix.Matrix[i];
245 }
246 return Result;
247 }
248
249 void GetMatrixDouble(double* OutMatrix) const
250 {
251 memcpy(OutMatrix, Matrix, 16 * sizeof(double));
252 }
253
255 {
256 return FVector(Get(0, Index), Get(1, Index), Get(2, Index));
257 }
258
260 {
261 return FVector(Get(Index, 0), Get(Index, 1), Get(Index, 2));
262 }
263
264 void Print(EVerboseLevel level) const;
265
266 bool IsId() const
267 {
268 for (int32 Row = 0; Row < 4; Row++)
269 {
270 for (int32 Column = 0; Column < 4; Column++)
271 {
272 if (Row == Column)
273 {
274 if (!FMath::IsNearlyEqual(Get(Row, Column), 1.)) return false;
275 }
276 else
277 {
278 if (!FMath::IsNearlyZero(Get(Row, Column))) return false;
279 }
280 }
281 }
282 return true;
283 }
284};
285
287
289
291
292} // namespace UE::CADKernel
293
GLenum GLuint GLint level
Definition AndroidOpenGLFunctions.h:46
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define FVector
Definition IOSSystemIncludes.h:8
UE::Math::TVector< float > FVector3f
Definition MathFwd.h:73
UE::Math::TVector2< double > FVector2d
Definition MathFwd.h:61
void Move(T &A, typename TMoveSupportTraits< T >::Copy B)
Definition UnrealTemplate.h:24
memcpy(InputBufferBase, BinkBlocksData, BinkBlocksSize)
Definition Archive.h:1208
virtual void Serialize(void *V, int64 Length)
Definition Archive.h:1689
Definition MatrixH.h:14
FMatrixH(const double *const InMatrix16)
Definition MatrixH.h:27
FVector3f MultiplyVector(const FVector3f &InVector) const
Definition MatrixH.h:119
void Inverse()
Definition MatrixH.cpp:114
FVector Multiply(const FVector2d &Point2D) const
Definition MatrixH.h:88
double operator()(int32 Row, int32 Column) const
Definition MatrixH.h:200
FVector operator*(const FVector &Point) const
Definition MatrixH.h:234
void SetIdentity()
Definition MatrixH.h:57
FMatrixH GetInverse() const
Definition MatrixH.h:166
FMatrixH operator*(const FMatrixH &InMatrix) const
Definition MatrixH.h:210
double & operator[](int32 Index)
Definition MatrixH.h:205
FVector Column(int32 Index) const
Definition MatrixH.h:254
friend FArchive & operator<<(FArchive &Ar, FMatrixH &InMatrix)
Definition MatrixH.h:51
FVector MultiplyVector(const FVector2d &Point2D) const
Definition MatrixH.h:108
double & Get(int32 Row, int32 Column)
Definition MatrixH.h:185
FMatrixH(const double InMatrix44[][4])
Definition MatrixH.h:35
double Get(int32 Row, int32 Column) const
Definition MatrixH.h:190
FVector Multiply(const FVector &InPoint) const
Definition MatrixH.h:79
FMatrixH(const FVector &Origin, const FVector &Ox, const FVector &Oy, const FVector &Oz)
Definition MatrixH.h:46
void operator*=(const FMatrixH &InMatrix)
Definition MatrixH.h:228
FVector PointRotation(const FVector &PointToRotate, const FVector &Origin) const
Definition MatrixH.h:138
FVector2d MultiplyVector2D(const FVector2d &Point2D) const
Definition MatrixH.h:113
static const FMatrixH Identity
Definition MatrixH.h:20
FMatrixH()
Definition MatrixH.h:22
FVector2d Multiply2D(const FVector2d &Point2D) const
Definition MatrixH.h:93
double & operator()(int32 Row, int32 Column)
Definition MatrixH.h:195
FVector2d PointRotation(const FVector2d &PointToRotate, const FVector2d &Origin) const
Definition MatrixH.h:151
FVector Row(int32 Index) const
Definition MatrixH.h:259
void GetMatrixDouble(double *OutMatrix) const
Definition MatrixH.h:249
FVector MultiplyVector(const FVector &InVector) const
Definition MatrixH.h:99
FMatrixH operator+(const FMatrixH &InMatrix) const
Definition MatrixH.h:239
bool IsId() const
Definition MatrixH.h:266
void Transpose()
Definition MatrixH.h:173
Definition CADEntity.cpp:23
void MatrixProduct(int32 ARowNum, int32 AColumnNum, int32 ResultRank, const double *MatrixA, const double *MatrixB, double *MatrixResult)
Definition MatrixH.cpp:228
void InverseMatrixN(double *Matrice, int32 Rank)
Definition MatrixH.cpp:133
void TransposeMatrix(int32 RowNum, int32 ColumnNum, const double *InMatrix, double *OutMatrix)
Definition MatrixH.cpp:245
EVerboseLevel
Definition Types.h:104
U16 Index
Definition radfft.cpp:71
static UE_FORCEINLINE_HINT bool IsNearlyEqual(float A, float B, float ErrorTolerance=UE_SMALL_NUMBER)
Definition UnrealMathUtility.h:388
static UE_FORCEINLINE_HINT bool IsNearlyZero(float Value, float ErrorTolerance=UE_SMALL_NUMBER)
Definition UnrealMathUtility.h:407
T Z
Definition Vector.h:68
T Y
Definition Vector.h:65
T X
Definition Vector.h:62