Matrix4 — Aspose.3D FOSS for Java

Example

Matrix4 เป็นเมทริกซ์ 4x4 แบบ double-precision ที่ใช้สำหรับการแปลงเชิง affine ในพื้นที่ 3 มิติ มันถูกส่งคืนโดย Transform.getTransformMatrix() และ GlobalTransform.getTransformMatrix(), และสามารถสร้างได้จากการแยกส่วนการแปล, การหมุน, และการสเกล (TRS).

Example: com.aspose.threed

import com.aspose.threed.*;

Example

ExampleExample
Matrix4()สร้างเมทริกซ์เอกลักษณ์
Matrix4(double m00, double m01, ... double m33)โครงสร้างจาก 16 องค์ประกอบเดี่ยว (row-major)

ฟิลด์สถิตย์

ExampleExampleExample
IDENTITYMatrix4เมทริกซ์เอกลักษณ์ 4x4

ฟิลด์สาธารณะ (การเข้าถึงองค์ประกอบ)

Matrix4 ใช้ ฟิลด์สาธารณะ สำหรับการเข้าถึงองค์ประกอบ: m00, m01, … m33 (รวม 16 ฟิลด์, การจัดเรียงแบบแถวหลัก).

รูปแบบฟิลด์ExampleExample
m00m33doubleองค์ประกอบเมทริกซ์แต่ละตัวเป็นฟิลด์สาธารณะ เข้าถึงเป็น mat.m00, mat.m01, ฯลฯ.

ส่วนประกอบการแปลอยู่ในคอลัมน์สุดท้าย: m03 (X), m13 (Y), m23 (Z).

Example

Exampleประเภทการคืนค่าExample
multiply(Matrix4 other)Matrix4การคูณเมทริกซ์; ส่งคืนเมทริกซ์ใหม่
inverse()Matrix4คืนเมทริกซ์ผกผัน
transpose()Matrix4คืนเมทริกซ์ที่ทำการสลับแถวและคอลัมน์
decompose(Vector3 translation, Vector3 scaling, Quaternion rotation)booleanโค้ดจำลอง: จะคืนค่าเสมอ false. มีจุดประสงค์เพื่อแยกเมทริกซ์เป็นส่วนประกอบ TRS แต่ยังไม่ได้ทำการใช้งาน.
determinant()doubleคืนค่าดีเทอร์มิแนนต์ของเมทริกซ์
transformPoint(Vector3 point)Vector3แปลงจุด (ใช้การแปลทั้งหมด + การหมุน + การสเกล)
transformDirection(Vector3 direction)Vector3แปลงเวกเตอร์ทิศทาง (ใช้การหมุน + การสเกล, ไม่สนใจการแปล)

เมธอดสถิตย์

Exampleประเภทค่าที่คืนExample
Matrix4.translate(Vector3 t)Matrix4สร้างเมทริกซ์การแปล
Matrix4.translate(double x, double y, double z)Matrix4สร้างเมทริกซ์การแปลจากส่วนประกอบ
Matrix4.scale(Vector3 s)Matrix4สร้างเมทริกซ์สเกล
Matrix4.scale(double x, double y, double z)Matrix4สร้างเมทริกซ์สเกลจากส่วนประกอบ
Matrix4.rotateFromQuaternion(Quaternion q)Matrix4สร้างเมทริกซ์การหมุนจาก quaternion

Example

import com.aspose.threed.*;

Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("box");
node.getTransform().setTranslation(1.0, 2.0, 3.0);
node.getTransform().setEulerAngles(0.0, 45.0, 0.0);

// Read the transform matrix
Matrix4 m = node.getTransform().getTransformMatrix();
System.out.println("Translation X: " + m.m03);   // 1.0

// Matrix multiplication
Matrix4 translate = Matrix4.translate(5.0, 0.0, 0.0);
Matrix4 scale = Matrix4.scale(2.0, 2.0, 2.0);
Matrix4 combined = translate.multiply(scale);

// Inverse
Matrix4 inv = m.inverse();

// Transform a point
Vector3 point = new Vector3(1.0, 0.0, 0.0);
Vector3 transformed = m.transformPoint(point);
System.out.println(transformed);

ดูเพิ่มเติม

 ภาษาไทย