Hướng dẫn slerp python - con trăn nhỏ

Xem bài viết Wikipedia cho toàn bộ toán học bậc bốn.

Không biết bạn muốn sử dụng ngôn ngữ nào nhưng tôi sẽ cố gắng đưa ra một số gợi ý trong Haskell.

data Quaternion = Q Double Double Double Double deriving (Show, Eq)

Đầu tiên, bạn cần thực hiện phép nhân và bổ sung các bậc bốn.

instance Num Quaternion where
 (+) = q_plus
 (*) = q_mult
 --....

q_plus (Q a b c d) (Q a' b' c' d') = Q (a + a') (b + b') (c + c') (d + d')
q_mult (Q a b c d) (Q a' b' c' d') = Q a'' b'' c'' d''
  where
    a'' = a * a' - b * b' - c * c' - d * d'
    b'' = a * b' + b * a' + c * d' - d * c'
    c'' = a * c' - b * d' + c * a' + d * b'
    d'' = a * d' + b * c' - c * b' + d * a'

Việc nhân với vô hướng nên được thực hiện thông qua chuyển đổi:

scalar_to_q a = Q a 0 0 0

Định nghĩa

i = Q 0 1 0 0
j = Q 0 0 1 0
k = Q 0 0 0 1

Sau đó thực hiện liên hợp và mô đun:

q_conjugate q = (scalar_to_q (negate .5)) * (q + i * q * i + j * q * j + k * q * k)
q_modulus q = sqrt $ q * (q_conjugate q)

Bây giờ, nghịch đảo:

q_inverse q = (q_conjugate q) * (scalar_to_q (m * m))
  where
    m = q_modulus q

Hy vọng nó hữu ích.

PS: Định nghĩa trường hợp ở trên sẽ đơn giản hóa mọi thứ một chút nếu hoàn thành thành công. Tôi cho phép bạn điền vào các khoảng trống.

________ 6 ________ 33 (*args, ** kwargs) [Nguồn] ¶

Tính toán số mũ của bậc bốn

quat (numpy.array) - Quê vị.(*args, **kwargs)[source]¶(*args, **kwargs)[source]¶(*args, **kwargs)[source]

numpy.array.

Parameters:
  • quat (numpy.array) - Quê vị. (numpy.array) – The quaternion. (numpy.array) – The quaternion. (numpy.array) – The quaternion.
  • vec (numpy.array) - vector. (numpy.array) – The vector. (numpy.array) – The vector. (numpy.array) – The vector.
Loại trở lại:

numpy.array

Returns:

Các vectơ xoay bởi bậc bốn.

Raises:

ValueError - được nâng lên nếu vectơ có kích thước không được hỗ trợ – raised if the vector is an unsupported size – raised if the vector is an unsupported size – raised if the vector is an unsupported size

________ 6 ________ 9 (*args, ** kwargs) [nguồn](*args, **kwargs)[source]¶(*args, **kwargs)[source]¶(*args, **kwargs)[source]

Tính toán một bậc bốn với vòng quay đối diện.

Parameters:quat (numpy.array) - Quê vị. (numpy.array) – The quaternion. (numpy.array) – The quaternion. (numpy.array) – The quaternion.
Loại trở lại:Các vectơ xoay bởi bậc bốn.
Returns:ValueError - được nâng lên nếu vectơ có kích thước không được hỗ trợ – raised if the vector is an unsupported size – raised if the vector is an unsupported size
________ 6 ________ 9 (*args, ** kwargs) [nguồn](*args, **kwargs)[source]¶(*args, **kwargs)[source]¶(x=0.0, y=0.0, z=0.0, w=1.0, dtype=None)[source]
instance Num Quaternion where
 (+) = q_plus
 (*) = q_mult
 --....

q_plus (Q a b c d) (Q a' b' c' d') = Q (a + a') (b + b') (c + c') (d + d')
q_mult (Q a b c d) (Q a' b' c' d') = Q a'' b'' c'' d''
  where
    a'' = a * a' - b * b' - c * c' - d * d'
    b'' = a * b' + b * a' + c * d' - d * c'
    c'' = a * c' - b * d' + c * a' + d * b'
    d'' = a * d' + b * c' - c * b' + d * a'
5
instance Num Quaternion where
 (+) = q_plus
 (*) = q_mult
 --....

q_plus (Q a b c d) (Q a' b' c' d') = Q (a + a') (b + b') (c + c') (d + d')
q_mult (Q a b c d) (Q a' b' c' d') = Q a'' b'' c'' d''
  where
    a'' = a * a' - b * b' - c * c' - d * d'
    b'' = a * b' + b * a' + c * d' - d * c'
    c'' = a * c' - b * d' + c * a' + d * b'
    d'' = a * d' + b * c' - c * b' + d * a'
3(*args, **kwargs)[source]
instance Num Quaternion where
 (+) = q_plus
 (*) = q_mult
 --....

q_plus (Q a b c d) (Q a' b' c' d') = Q (a + a') (b + b') (c + c') (d + d')
q_mult (Q a b c d) (Q a' b' c' d') = Q a'' b'' c'' d''
  where
    a'' = a * a' - b * b' - c * c' - d * d'
    b'' = a * b' + b * a' + c * d' - d * c'
    c'' = a * c' - b * d' + c * a' + d * b'
    d'' = a * d' + b * c' - c * b' + d * a'
5
instance Num Quaternion where
 (+) = q_plus
 (*) = q_mult
 --....

q_plus (Q a b c d) (Q a' b' c' d') = Q (a + a') (b + b') (c + c') (d + d')
q_mult (Q a b c d) (Q a' b' c' d') = Q a'' b'' c'' d''
  where
    a'' = a * a' - b * b' - c * c' - d * d'
    b'' = a * b' + b * a' + c * d' - d * c'
    c'' = a * c' - b * d' + c * a' + d * b'
    d'' = a * d' + b * c' - c * b' + d * a'
5(*args, **kwargs)[source]
instance Num Quaternion where
 (+) = q_plus
 (*) = q_mult
 --....

q_plus (Q a b c d) (Q a' b' c' d') = Q (a + a') (b + b') (c + c') (d + d')
q_mult (Q a b c d) (Q a' b' c' d') = Q a'' b'' c'' d''
  where
    a'' = a * a' - b * b' - c * c' - d * d'
    b'' = a * b' + b * a' + c * d' - d * c'
    c'' = a * c' - b * d' + c * a' + d * b'
    d'' = a * d' + b * c' - c * b' + d * a'
5
instance Num Quaternion where
 (+) = q_plus
 (*) = q_mult
 --....

q_plus (Q a b c d) (Q a' b' c' d') = Q (a + a') (b + b') (c + c') (d + d')
q_mult (Q a b c d) (Q a' b' c' d') = Q a'' b'' c'' d''
  where
    a'' = a * a' - b * b' - c * c' - d * d'
    b'' = a * b' + b * a' + c * d' - d * c'
    c'' = a * c' - b * d' + c * a' + d * b'
    d'' = a * d' + b * c' - c * b' + d * a'
7(*args, **kwargs)[source]

Tính toán một bậc bốn với vòng quay đối diện.

quat (numpy.array) - Quê vị.(*args, **kwargs)[source]¶(*args, **kwargs)[source]¶(*args, **kwargs)[source]

numpy.array.

quat (numpy.array) - Quê vị. (numpy.array) – The quaternion. (numpy.array) – The quaternion.(*args, **kwargs)[source]
instance Num Quaternion where
 (+) = q_plus
 (*) = q_mult
 --....

q_plus (Q a b c d) (Q a' b' c' d') = Q (a + a') (b + b') (c + c') (d + d')
q_mult (Q a b c d) (Q a' b' c' d') = Q a'' b'' c'' d''
  where
    a'' = a * a' - b * b' - c * c' - d * d'
    b'' = a * b' + b * a' + c * d' - d * c'
    c'' = a * c' - b * d' + c * a' + d * b'
    d'' = a * d' + b * c' - c * b' + d * a'
5
scalar_to_q a = Q a 0 0 0
3(theta, dtype=None)[source]
instance Num Quaternion where
 (+) = q_plus
 (*) = q_mult
 --....

q_plus (Q a b c d) (Q a' b' c' d') = Q (a + a') (b + b') (c + c') (d + d')
q_mult (Q a b c d) (Q a' b' c' d') = Q a'' b'' c'' d''
  where
    a'' = a * a' - b * b' - c * c' - d * d'
    b'' = a * b' + b * a' + c * d' - d * c'
    c'' = a * c' - b * d' + c * a' + d * b'
    d'' = a * d' + b * c' - c * b' + d * a'
5
scalar_to_q a = Q a 0 0 0
5(theta, dtype=None)[source]
instance Num Quaternion where
 (+) = q_plus
 (*) = q_mult
 --....

q_plus (Q a b c d) (Q a' b' c' d') = Q (a + a') (b + b') (c + c') (d + d')
q_mult (Q a b c d) (Q a' b' c' d') = Q a'' b'' c'' d''
  where
    a'' = a * a' - b * b' - c * c' - d * d'
    b'' = a * b' + b * a' + c * d' - d * c'
    c'' = a * c' - b * d' + c * a' + d * b'
    d'' = a * d' + b * c' - c * b' + d * a'
5
scalar_to_q a = Q a 0 0 0
7(theta, dtype=None)[source]
instance Num Quaternion where
 (+) = q_plus
 (*) = q_mult
 --....

q_plus (Q a b c d) (Q a' b' c' d') = Q (a + a') (b + b') (c + c') (d + d')
q_mult (Q a b c d) (Q a' b' c' d') = Q a'' b'' c'' d''
  where
    a'' = a * a' - b * b' - c * c' - d * d'
    b'' = a * b' + b * a' + c * d' - d * c'
    c'' = a * c' - b * d' + c * a' + d * b'
    d'' = a * d' + b * c' - c * b' + d * a'
5
scalar_to_q a = Q a 0 0 0
9(*args, **kwargs)[source]

vec (numpy.array) - vector. (numpy.array) – The vector. (numpy.array) – The vector.

Loại trở lại:not communicative. Therefore, order is important.

Các vectơ xoay bởi bậc bốn.

ValueError - được nâng lên nếu vectơ có kích thước không được hỗ trợ – raised if the vector is an unsupported size – raised if the vector is an unsupported size(quat1, quat2)[source]

________ 6 ________ 9 (*args, ** kwargs) [nguồn](*args, **kwargs)[source]¶(*args, **kwargs)[source]¶

Tính toán một bậc bốn với vòng quay đối diện.

Parameters:
  • quat (numpy.array) - Quê vị. (numpy.array) – The quaternion. (numpy.array) – The quaternion. (numpy.array) – The first quaternion(s).
  • Các vectơ xoay bởi bậc bốn. (numpy.array) – The second quaternion(s).
Loại trở lại:

Các vectơ xoay bởi bậc bốn.

Returns:

ValueError - được nâng lên nếu vectơ có kích thước không được hỗ trợ – raised if the vector is an unsupported size – raised if the vector is an unsupported size

________ 6 ________ 9 (*args, ** kwargs) [nguồn](*args, **kwargs)[source]¶(*args, **kwargs)[source]¶(*args, **kwargs)[source]

Tính toán một bậc bốn với vòng quay đối diện.

Parameters:quat (numpy.array) - Quê vị. (numpy.array) – The quaternion. (numpy.array) – The quaternion. (numpy.array) – The quaternion.
Loại trở lại:Các vectơ xoay bởi bậc bốn.
Returns:ValueError - được nâng lên nếu vectơ có kích thước không được hỗ trợ – raised if the vector is an unsupported size – raised if the vector is an unsupported size
________ 6 ________ 9 (*args, ** kwargs) [nguồn](*args, **kwargs)[source]¶(*args, **kwargs)[source]¶[source]
i = Q 0 1 0 0
j = Q 0 0 1 0
k = Q 0 0 0 1
6 = 3¶

Tính toán một bậc bốn với vòng quay đối diện.

quat (numpy.array) - Quê vị. (numpy.array) – The quaternion. (numpy.array) – The quaternion.

numpy.array.

Các vectơ xoay bởi bậc bốn.

vec (numpy.array) - vector. (numpy.array) – The vector. (numpy.array) – The vector.

Loại trở lại:

Các vectơ xoay bởi bậc bốn.

ValueError - được nâng lên nếu vectơ có kích thước không được hỗ trợ – raised if the vector is an unsupported size – raised if the vector is an unsupported size(quat)[source]

________ 6 ________ 9 (*args, ** kwargs) [nguồn](*args, **kwargs)[source]¶(*args, **kwargs)[source]¶

Tính toán một bậc bốn với vòng quay đối diện.

Parameters:quat (numpy.array) - Quê vị. (numpy.array) – The quaternion. (numpy.array) – The quaternion. (numpy.array) – The quaternion to invert.
Loại trở lại:Các vectơ xoay bởi bậc bốn.
Returns:ValueError - được nâng lên nếu vectơ có kích thước không được hỗ trợ – raised if the vector is an unsupported size – raised if the vector is an unsupported size
________ 6 ________ 9 (*args, ** kwargs) [nguồn](*args, **kwargs)[source]¶(*args, **kwargs)[source]¶(quat)[source]
instance Num Quaternion where
 (+) = q_plus
 (*) = q_mult
 --....

q_plus (Q a b c d) (Q a' b' c' d') = Q (a + a') (b + b') (c + c') (d + d')
q_mult (Q a b c d) (Q a' b' c' d') = Q a'' b'' c'' d''
  where
    a'' = a * a' - b * b' - c * c' - d * d'
    b'' = a * b' + b * a' + c * d' - d * c'
    c'' = a * c' - b * d' + c * a' + d * b'
    d'' = a * d' + b * c' - c * b' + d * a'
5
q_conjugate q = (scalar_to_q (negate .5)) * (q + i * q * i + j * q * j + k * q * k)
q_modulus q = sqrt $ q * (q_conjugate q)
5(quat)[source]

Tính toán một bậc bốn với vòng quay đối diện.

quat (numpy.array) - Quê vị. (numpy.array) – The quaternion. (numpy.array) – The quaternion.

Parameters:Các vectơ xoay bởi bậc bốn. (numpy.array) – The quaternion to check. (numpy.array) – The quaternion to check.
Loại trở lại:Các vectơ xoay bởi bậc bốn.
Returns:________ 6 ________ 11 (x = 0,0, y = 0,0, z = 0,0, w = 1.0, dtype = none) [nguồn] ] ________ 6 ________ 17 (*args, ** kwargs) [nguồn] ¶
Tạo một bậc bốn từ một tập hợp các góc Euler.(quat)[source]¶(quat)[source]¶(quat)[source]

Eulers là một mảng có độ dài 3 theo thứ tự sau: [cuộn, cao độ, ngáp] ________ 6 ________ 19 (*args, ** kwargs) [nguồn]

Parameters:numpy.array. (numpy.array) – The quaternion to check. (numpy.array) – The quaternion to check. (numpy.array) – The quaternion to check.
Loại trở lại:Các vectơ xoay bởi bậc bốn.
Returns:________ 6 ________ 11 (x = 0,0, y = 0,0, z = 0,0, w = 1.0, dtype = none) [nguồn] ] ________ 6 ________ 17 (*args, ** kwargs) [nguồn] ¶
Tạo một bậc bốn từ một tập hợp các góc Euler.(quat)[source]¶(quat)[source]¶(quat)[source]

Eulers là một mảng có độ dài 3 theo thứ tự sau: [cuộn, cao độ, ngáp] ________ 6 ________ 19 (*args, ** kwargs) [nguồn]

Parameters:numpy.array. (numpy.array) – The quaternion to check. (numpy.array) – The quaternion to check. (numpy.array) – The quaternion to measure.
Loại trở lại:Các vectơ xoay bởi bậc bốn.
Returns:________ 6 ________ 11 (x = 0,0, y = 0,0, z = 0,0, w = 1.0, dtype = none) [nguồn] ] ________ 6 ________ 17 (*args, ** kwargs) [nguồn] ¶
Tạo một bậc bốn từ một tập hợp các góc Euler.(quat)[source]¶(quat)[source]¶(quat1, quat2, t)[source]

Eulers là một mảng có độ dài 3 theo thứ tự sau: [cuộn, cao độ, ngáp] ________ 6 ________ 19 (*args, ** kwargs) [nguồn]

numpy.array. (numpy.array) – The quaternion to check. (numpy.array) – The quaternion to check. (*args, **kwargs)[source]

Một bậc bốn đại diện cho liên hợp.

numpy.array. (numpy.array) – The quaternion to check. (numpy.array) – The quaternion to measure.

Parameters:Tạo một bậc bốn từ nghịch đảo của một tập hợp các góc Euler. (numpy.array) – The quaternion to measure. (numpy.array) – The quaternion.
Loại trở lại:Các vectơ xoay bởi bậc bốn.
Returns:________ 6 ________ 11 (x = 0,0, y = 0,0, z = 0,0, w = 1.0, dtype = none) [nguồn] ] ________ 6 ________ 17 (*args, ** kwargs) [nguồn] ¶
Tạo một bậc bốn từ một tập hợp các góc Euler.(quat)[source]¶(quat)[source]¶(quat)[source]

Eulers là một mảng có độ dài 3 theo thứ tự sau: [cuộn, cao độ, ngáp] ________ 6 ________ 19 (*args, ** kwargs) [nguồn]

numpy.array. (numpy.array) – The quaternion to check. (numpy.array) – The quaternion to check. not changed in place.

Parameters:Một bậc bốn đại diện cho liên hợp. (numpy.array) – The quaternion to normalize.
Loại trở lại:Các vectơ xoay bởi bậc bốn.
Returns:________ 6 ________ 11 (x = 0,0, y = 0,0, z = 0,0, w = 1.0, dtype = none) [nguồn] ] ________ 6 ________ 17 (*args, ** kwargs) [nguồn] ¶
Tạo một bậc bốn từ một tập hợp các góc Euler.(quat)[source]¶(quat)[source]¶(quat)[source]

Eulers là một mảng có độ dài 3 theo thứ tự sau: [cuộn, cao độ, ngáp] ________ 6 ________ 19 (*args, ** kwargs) [nguồn]

numpy.array. (numpy.array) – The quaternion to check. (numpy.array) – The quaternion to check. not changed in place.

Parameters:Một bậc bốn đại diện cho liên hợp. (numpy.array) – The quaternion to normalize.
Loại trở lại:Các vectơ xoay bởi bậc bốn.
Returns:________ 6 ________ 11 (x = 0,0, y = 0,0, z = 0,0, w = 1.0, dtype = none) [nguồn] ] ________ 6 ________ 17 (*args, ** kwargs) [nguồn] ¶
Tạo một bậc bốn từ một tập hợp các góc Euler.(quat)[source]¶(quat)[source]¶(*args, **kwargs)[source]

Eulers là một mảng có độ dài 3 theo thứ tự sau: [cuộn, cao độ, ngáp] ________ 6 ________ 19 (*args, ** kwargs) [nguồn]

numpy.array. (numpy.array) – The quaternion to check. (numpy.array) – The quaternion to check. not changed in place.

Parameters:
  • Một bậc bốn đại diện cho liên hợp. (numpy.array) – The quaternion.
  • numpy.array. (numpy.array) – The quaternion to check. (numpy.array) – The quaternion to measure. (float) – The exponent.
Loại trở lại:

numpy.array.

Returns:

Các vectơ xoay bởi bậc bốn.

________ 6 ________ 11 (x = 0,0, y = 0,0, z = 0,0, w = 1.0, dtype = none) [nguồn] ] ________ 6 ________ 17 (*args, ** kwargs) [nguồn] ¶ (quat)[source]

Tạo một bậc bốn từ một tập hợp các góc Euler.(quat)[source]¶(quat)[source]¶

Parameters:Tạo một bậc bốn từ nghịch đảo của một tập hợp các góc Euler. (numpy.array) – The quaternion to measure. (numpy.array) – The quaternion.
Loại trở lại:Các vectơ xoay bởi bậc bốn.
Returns:________ 6 ________ 11 (x = 0,0, y = 0,0, z = 0,0, w = 1.0, dtype = none) [nguồn] ] ________ 6 ________ 17 (*args, ** kwargs) [nguồn] ¶
Eulers là một mảng có độ dài 3 theo thứ tự sau: [cuộn, cao độ, ngáp] ____ ____ 6 ____ ____ 21 (*args, ** kwargs) [nguồn] Không có) [Nguồn] ____ ____ 6 ________ 27 (theta, dtype = none) (*args, **kwargs)[source]¶(*args, **kwargs)[source]

Trả về sản phẩm chéo của hai bậc bốn.

Parameters:Tính toán sản phẩm chấm của Đệ tứ. (numpy.array) – The quaternion. (numpy.array) – The quaternion.
Loại trở lại:Điều này giống như một sản phẩm chấm vector.
Returns:quat (numpy.array) - Quê vị. (numpy.array) – The quaternion.
Quat1 (Numpy.Array) - Đệ tứ đầu tiên. (quat1, quat2, t)[source]¶(quat1, quat2, t)[source]

Quat2 (numpy.array) - Quê vị thứ hai (s).

Phao, numpy.array(quat)[source]¶(quat)[source]¶(quat)[source]

Nếu một mảng 1D được thông qua, nó sẽ là một vô hướng. Nếu không, kết quả sẽ là một mảng vô hướng với hình dạng vec.ndim với kích thước cuối cùng là kích thước 1.

________ 6 ________ 33 (*args, ** kwargs) [Nguồn] ¶not changed in place.

Parameters:Tính toán số mũ của bậc bốn (numpy.array) – The quaternion to normalize. (numpy.array) – The quaternion to measure. (numpy.array) – The quaternion to measure.
Loại trở lại:Điều này giống như một sản phẩm chấm vector.
Returns:quat (numpy.array) - Quê vị. (numpy.array) – The quaternion.