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

MethodsMethods
Vector3()สร้างเวกเตอร์ศูนย์ (0, 0, 0)
Vector3(x, y, z)สร้างจากสาม float ส่วนประกอบ
Vector3(other)คอนสตรัคเตอร์คัดลอก — รับอีกหนึ่ง Vector3

Methods

ส่วนประกอบทั้งหมดเป็นคุณสมบัติที่สามารถอ่านและเขียนได้; เข้าถึงพวกมันโดยไม่ต้องใช้วงเล็บ.

MethodsMethodsMethods
xfloatส่วนประกอบ X
yfloatส่วนประกอบ Y
zfloatส่วนประกอบ Z
lengthfloatความยาวยูคลิด (sqrt(x²+y²+z²)), อ่านอย่างเดียว
length2floatความยาวกำลังสอง (x²+y²+z²), อ่านอย่างเดียว; มีต้นทุนต่ำกว่า length เมื่อเพียงต้องการการเปรียบเทียบ
zeroVector3Methods Vector3(0, 0, 0)
oneVector3Methods Vector3(1, 1, 1)
unit_xVector3Methods Vector3(1, 0, 0)
unit_yVector3Methods Vector3(0, 1, 0)
unit_zVector3Methods 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)

ดูเพิ่มเติม

 ภาษาไทย