作業描述
給定一個點P=(2,1), 將該點繞原點先逆時針旋轉45◦,再平移(1,2), 計算出變換后點的坐標(要求用齊次坐標進行計算)。
UE4 知識點
-
主要矩陣
- FMatrix
- FBasisVectorMatrix
- FLookFromMatrix
- FOrthoMatrix
- FReversedZOrthoMatrix
- FPerspectiveMatrix
- FReversedZPerspectiveMatrix
- FScaleMatrix
- FTranslationMatrix
- FRotationTranslationMatrix
- FRotationMatrix
- FInverseRotationMatrix
- PMatrix
- FMatrix2x2
- FMatrix
-
FMatrix 矩陣說明
以行向量作為計算習慣,所以計算的時候矩陣注意取轉置
代碼實現
-
版本 4.26.2
-
藍圖
-
C++
void AActor_Pa0::BeginPlay() { Super::BeginPlay(); // 給定一個點P=(2,1), 將該點繞原點先逆時針旋轉45◦,再平移(1,2), 計算出變換后點的坐標(要求用齊次坐標進行計算)。 float fcos = UKismetMathLibrary::DegCos(45); float fsin = UKismetMathLibrary::DegSin(45); FPlane row1 = FPlane(fcos, -fsin, 1, 0); FPlane row2 = FPlane(fsin, fcos, 2, 0); FPlane row3 = FPlane(0, -0, 1, 0); FPlane row4 = FPlane(0, -0, 0, 0); FMatrix matrix = FMatrix(row1, row2, row3, row4); FVector4 originPos = FVector4(2, 1, 1, 0); matrix = matrix.GetTransposed(); //行向量乘以矩陣,所以矩陣取轉置 FVector4 res = matrix.TransformFVector4(originPos); UE_LOG(LogTemp, Warning, TEXT("%s"), *matrix.ToString()); UE_LOG(LogTemp, Warning, TEXT("[ %f, %f, %f ]"), res.X, res.Y, res.Z); }
output: LogTemp: Warning: [0.707107 0.707107 0 0] [-0.707107 0.707107 0 0] [1 2 1 0] [0 0 0 0] LogTemp: Warning: [ 1.707107, 4.121320, 1.000000 ]