Vector3
Methods
Vector3 เป็นเวกเตอร์ 3 ส่วนประกอบแบบ double-precision ที่มี x, y, และ z ส่วนประกอบ. มันถูกใช้ทั่วทั้ง Aspose.3D สำหรับตำแหน่ง, ทิศทาง, เวกเตอร์ปกติ, และค่าการสเกล. การดำเนินการเชิงคณิตศาสตร์ทั้งหมดจะคืนค่าอินสแตนซ์ใหม่ Vector3 อินสแตนซ์; ตัวต้นฉบับจะไม่ถูกเปลี่ยนแปลง.
from aspose.threed.utilities import Vector3
# Construct from components
v = Vector3(1.0, 2.0, 3.0)
# Copy constructor
v2 = Vector3(v)
# Default (zero vector)
zero = Vector3()Methods
| Methods | Methods |
|---|---|
Vector3() | สร้างเวกเตอร์ศูนย์ (0, 0, 0) |
Vector3(x, y, z) | สร้างจากสาม float ส่วนประกอบ |
Vector3(other) | คอนสตรัคเตอร์คัดลอก — รับอีกหนึ่ง Vector3 |
Methods
ส่วนประกอบทั้งหมดเป็นคุณสมบัติที่สามารถอ่านและเขียนได้; เข้าถึงพวกมันโดยไม่ต้องใช้วงเล็บ.
| Methods | Methods | Methods |
|---|---|---|
x | float | ส่วนประกอบ X |
y | float | ส่วนประกอบ Y |
z | float | ส่วนประกอบ Z |
length | float | ความยาวยูคลิด (sqrt(x²+y²+z²)), อ่านอย่างเดียว |
length2 | float | ความยาวกำลังสอง (x²+y²+z²), อ่านอย่างเดียว; มีต้นทุนต่ำกว่า length เมื่อเพียงต้องการการเปรียบเทียบ |
zero | Vector3 | Methods Vector3(0, 0, 0) |
one | Vector3 | Methods Vector3(1, 1, 1) |
unit_x | Vector3 | Methods Vector3(1, 0, 0) |
unit_y | Vector3 | Methods Vector3(0, 1, 0) |
unit_z | Vector3 | Methods Vector3(0, 0, 1) |
Methods
| Methods | ประเภทการคืนค่า | Methods |
|---|---|---|
set(x, y, z) | None | กำหนดส่วนประกอบทั้งสามในที่เดียว |
dot(rhs) | float | ผลคูณจุดกับเวกเตอร์อื่น Vector3 |
cross(rhs) | Vector3 | ผลคูณครอส — คืนค่าเวกเตอร์ที่ตั้งฉากกับตัวดำเนินการทั้งสอง |
normalize() | Vector3 | คืนค่ากลุ่มสำเนาความยาวหน่วย; คืนค่าเวกเตอร์ศูนย์หากความยาวเป็นศูนย์ |
angle_between(dir) | float | มุมเป็นเรเดียนระหว่างเวกเตอร์นี้และ dir |
angle_between(dir, up) | float | มุมที่มีเครื่องหมายเป็นเรเดียนที่ฉายลงบนระนาบที่กำหนดโดย up |
sin() | Vector3 | ไซน์ต่อส่วนประกอบ |
cos() | Vector3 | โคไซน์ต่อส่วนประกอบ |
compare_to(other) | int | การเปรียบเทียบตามลำดับอักขระ: คืนค่า −1, 0 หรือ 1 |
Vector3.parse(s) | Vector3 | แบบสแตติก. แยกวิเคราะห์ "x y z" การแสดงผลเป็นสตริง |
การเข้าถึงโดยดัชนี
สามารถเข้าถึงส่วนประกอบโดยใช้ดัชนีจำนวนเต็ม: v[0] → x, v[1] → y, v[2] → z.
Methods
from aspose.threed.utilities import Vector3
# Basic arithmetic (standard Python operators are supported)
a = Vector3(1.0, 0.0, 0.0)
b = Vector3(0.0, 1.0, 0.0)
# Dot and cross products
dot = a.dot(b) # 0.0
perp = a.cross(b) # Vector3(0, 0, 1)
# Normalize
direction = Vector3(3.0, 4.0, 0.0)
unit = direction.normalize() # Vector3(0.6, 0.8, 0.0)
print(unit.length) # 1.0
# Angle between vectors
import math
angle = a.angle_between(b)
print(math.degrees(angle)) # 90.0
# Use with a scene node transform
from aspose.threed import Scene
scene = Scene()
node = scene.root_node.create_child_node("box")
node.transform.translation = Vector3(10.0, 0.0, 0.0)