Quaternion

Methods

Quaternion מייצג קווטרניון יחיד המשמש לקידוד סיבובים תלת‑ממדיים. בניגוד לזוויות אוילר, קווטרניונים נמנעים מנעילת גימבל ומבצעים אינטרפולציה חלקה. ה Transform.rotation המאפיין על צומת סצנה מאחסן Quaternion.

הרכיבים מאוחסנים כ (w, x, y, z) כאשר w הוא החלק הסקלרי ו (x, y, z) מהווים את החלק הווקטורי.

from aspose.threed.utilities import Quaternion
import math

# Identity quaternion (no rotation)
q = Quaternion()   # w=1, x=0, y=0, z=0

# Rotation of 90 degrees around the Y axis
q = Quaternion.from_euler_angle(0.0, math.radians(90), 0.0)

Methods: aspose.threed.utilities

from aspose.threed.utilities import Quaternion

Methods

MethodsMethods
Quaternion()קווטרניון זהות (w=1, x=0, y=0, z=0)
Quaternion(w, x, y, z)בונה רכיבים מפורש

Methods

MethodsMethodsMethods
wfloatחלק סקלרי (אמיתי)
xfloatרכיב x של הווקטור
yfloatרכיב y של הווקטור
zfloatרכיב z של הווקטור
lengthfloatמגניטודה של הקווטרניון

מתודות יצרן סטטיות

Methodsסוג החזרהMethods
Quaternion.from_euler_angle(pitch, yaw, roll)Quaternionבונה מתוך זוויות אוילר ברדיאנים (pitch=X, yaw=Y, roll=Z). גם מקבל Vector3 כארגומנט הראשון
Quaternion.from_angle_axis(angle, axis)Quaternionבונים מזווית (רדיאנים) ו- Vector3 ציר
Quaternion.from_rotation(orig, dest)Quaternionסיבוב קשת הקצר ביותר מכיוון orig לכיוון dest
Quaternion.interpolate(t, from_q, to_q)Quaternionאינטרפולציית SLERP; t ב [0, 1]
Quaternion.slerp(t, v1, v2)Quaternionכינוי ל interpolate

מתודות מופע

Methodsסוג החזרהMethods
normalize()Quaternionמחזיר עותק באורך יחידה
conjugate()Quaternionמחזיר את הקונוגט (w, -x, -y, -z)
inverse()Quaternionמחזיר את ההפך הכפלי; מעלה ValueError אם האורך הוא אפס
dot(q)floatמכפלת נקודה עם קווטרניון נוסף
concat(rhs)Quaternionמכפלת המילטון (הרכבה של שני סיבובים)
euler_angles()Vector3מוציא זוויות אוילר (רדיאנים) כ Vector3(roll, pitch, yaw)
to_matrix(translation=None)Matrix4ממיר למטריצת סיבוב 4×4; באופן אופציונלי משלב תזוזה Vector3
to_angle_axis(angle, axis)Noneמפצל לזווית (רדיאנים) וציר; התוצאות נכתבות לרשימות של אלמנט יחיד angle[0] ו axis[0]

Methods

from aspose.threed import Scene
from aspose.threed.utilities import Quaternion, Vector3
import math

scene = Scene()
node = scene.root_node.create_child_node("rotated_box")

# Rotate 45 degrees around the Y axis
angle = math.radians(45)
q = Quaternion.from_euler_angle(0.0, angle, 0.0)
node.transform.rotation = q

# SLERP between two rotations
q_start = Quaternion.from_euler_angle(0, 0, 0)
q_end   = Quaternion.from_euler_angle(0, math.pi, 0)
q_mid   = Quaternion.slerp(0.5, q_start, q_end)

# Convert to matrix (useful for manual transforms)
mat = q.to_matrix()

# Extract Euler angles back
angles = q.euler_angles()   # Vector3(roll, pitch, yaw)
print(math.degrees(angles.y))   # ~45.0

ראה גם

 עברית