Открыть боковую панель
nikitronn
sverchok
Коммиты
4a6e77b2
Коммит
4a6e77b2
создал
Янв 05, 2019
по автору
DolphinDream
Просмотр файлов
Add Quadrance to Quaternion Math node, fix bug in QIN node and add normalize to QOUT
владелец
256d61a8
Изменения
4
Скрыть пробелы
Построчно
Рядом
docs/nodes/quaternion/quaternion_math.rst
Просмотр файла @
4a6e77b2
...
@@ -20,6 +20,7 @@ The available arithmetic operations and their corresponding inputs/outputs are:
...
@@ -20,6 +20,7 @@ The available arithmetic operations and their corresponding inputs/outputs are:
| INVERT | Q | Q | Invert a quaternion |
| INVERT | Q | Q | Invert a quaternion |
| NORMALIZE | Q | Q | Normalize a quaternion |
| NORMALIZE | Q | Q | Normalize a quaternion |
| SCALE | QS | Q | Scale a quaternion by given factor |
| SCALE | QS | Q | Scale a quaternion by given factor |
| QUADRANCE | Q | S | Quadrance of a quaternion |
| MAGNITUDE | Q | S | Magnitude of a quaternion |
| MAGNITUDE | Q | S | Magnitude of a quaternion |
+============+========+========+=====================================+
+============+========+========+=====================================+
...
@@ -144,12 +145,22 @@ S = (s if sw else 1, s if sx else 1, s if sy else 1, s if sz else 1)
...
@@ -144,12 +145,22 @@ S = (s if sw else 1, s if sx else 1, s if sy else 1, s if sz else 1)
scale(q, S) = (w * Sw, x * Sx, y * Sy, z * Sz)
scale(q, S) = (w * Sw, x * Sx, y * Sy, z * Sz)
* QUADRANCE : the quadreance of a quaternion
q = (w, x, y, z)
Quadrance(q) = w * w + x * x + y * y + z * z
Note: essentially this is the dot product of the quaternion with itself, and also equal to square of the magnitude.
* MAGNITUDE : the magnitude of a quaternion
* MAGNITUDE : the magnitude of a quaternion
q = (w, x, y, z)
q = (w, x, y, z)
Magnitude(q) = sqrt(w * w + x * x + y * y + z * z)
Magnitude(q) = sqrt(w * w + x * x + y * y + z * z)
Note: this is essentially the square root of the quadrance (the length of the quaternion).
Output
Output
======
======
...
...
nodes/quaternion/quaternion_in.py
Просмотр файла @
4a6e77b2
...
@@ -187,7 +187,7 @@ class SvQuaternionInNode(bpy.types.Node, SverchCustomTreeNode):
...
@@ -187,7 +187,7 @@ class SvQuaternionInNode(bpy.types.Node, SverchCustomTreeNode):
quaternionList
.
append
(
q
)
quaternionList
.
append
(
q
)
elif
self
.
mode
==
"AXISANGLE"
:
elif
self
.
mode
==
"AXISANGLE"
:
I
=
[
inputs
[
n
].
sv_get
()[
0
]
for
n
in
{
"Axis"
,
"Angle"
}
]
I
=
[
inputs
[
n
].
sv_get
()[
0
]
for
n
in
[
"Axis"
,
"Angle"
]
]
params
=
match_long_repeat
(
I
)
params
=
match_long_repeat
(
I
)
au
=
angleConversion
[
self
.
angleUnits
]
au
=
angleConversion
[
self
.
angleUnits
]
for
axis
,
angle
in
zip
(
*
params
):
for
axis
,
angle
in
zip
(
*
params
):
...
...
nodes/quaternion/quaternion_math.py
Просмотр файла @
4a6e77b2
...
@@ -48,7 +48,8 @@ operations = {
...
@@ -48,7 +48,8 @@ operations = {
# one quaternion + scalar => quaternion (QS => Q)
# one quaternion + scalar => quaternion (QS => Q)
"SCALE"
:
(
40
,
"QS"
,
"Q"
,
"Scale a quaternion by given factor"
),
"SCALE"
:
(
40
,
"QS"
,
"Q"
,
"Scale a quaternion by given factor"
),
# one quaternion => scalar value (Q => S)
# one quaternion => scalar value (Q => S)
"MAGNITUDE"
:
(
50
,
"Q"
,
"S"
,
"Magnitude of a quaternion"
),
"QUADRANCE"
:
(
50
,
"Q"
,
"S"
,
"Quadrance of a quaternion"
),
"MAGNITUDE"
:
(
51
,
"Q"
,
"S"
,
"Magnitude of a quaternion"
),
}
}
operationItems
=
[(
k
,
k
.
title
(),
s
[
3
],
""
,
s
[
0
])
for
k
,
s
in
sorted
(
operations
.
items
(),
key
=
lambda
k
:
k
[
1
][
0
])]
operationItems
=
[(
k
,
k
.
title
(),
s
[
3
],
""
,
s
[
0
])
for
k
,
s
in
sorted
(
operations
.
items
(),
key
=
lambda
k
:
k
[
1
][
0
])]
...
@@ -211,6 +212,8 @@ class SvQuaternionMathNode(bpy.types.Node, SverchCustomTreeNode):
...
@@ -211,6 +212,8 @@ class SvQuaternionMathNode(bpy.types.Node, SverchCustomTreeNode):
return
lambda
q
:
q
.
normalized
()
return
lambda
q
:
q
.
normalized
()
elif
self
.
operation
==
"SCALE"
:
elif
self
.
operation
==
"SCALE"
:
return
lambda
q
,
s
:
Quaternion
([
q
[
i
]
*
s
[
i
]
for
i
in
range
(
4
)])
return
lambda
q
,
s
:
Quaternion
([
q
[
i
]
*
s
[
i
]
for
i
in
range
(
4
)])
elif
self
.
operation
==
"QUADRANCE"
:
return
lambda
q
:
q
.
dot
(
q
)
elif
self
.
operation
==
"MAGNITUDE"
:
elif
self
.
operation
==
"MAGNITUDE"
:
return
lambda
q
:
q
.
magnitude
return
lambda
q
:
q
.
magnitude
...
@@ -249,11 +252,11 @@ class SvQuaternionMathNode(bpy.types.Node, SverchCustomTreeNode):
...
@@ -249,11 +252,11 @@ class SvQuaternionMathNode(bpy.types.Node, SverchCustomTreeNode):
operation
=
self
.
get_operation
()
operation
=
self
.
get_operation
()
if
self
.
operation
in
NQ_operations
:
# multiple input operations
if
self
.
operation
in
NQ_operations
:
parameters
=
match_long_repeat
(
I
)
parameters
=
match_long_repeat
(
I
)
quaternionList
=
[
operation
(
params
)
for
params
in
zip
(
*
parameters
)]
quaternionList
=
[
operation
(
params
)
for
params
in
zip
(
*
parameters
)]
elif
self
.
operation
in
QQ_operations
:
# multiple input operations
elif
self
.
operation
in
QQ_operations
:
parameters
=
match_long_repeat
(
I
)
parameters
=
match_long_repeat
(
I
)
quaternionList
=
[
operation
(
*
params
)
for
params
in
zip
(
*
parameters
)]
quaternionList
=
[
operation
(
*
params
)
for
params
in
zip
(
*
parameters
)]
...
...
nodes/quaternion/quaternion_out.py
Просмотр файла @
4a6e77b2
...
@@ -138,6 +138,8 @@ class SvQuaternionOutNode(bpy.types.Node, SverchCustomTreeNode):
...
@@ -138,6 +138,8 @@ class SvQuaternionOutNode(bpy.types.Node, SverchCustomTreeNode):
quaternionList
=
[
Quaternion
(
q
)
for
q
in
input_Q
]
quaternionList
=
[
Quaternion
(
q
)
for
q
in
input_Q
]
if
self
.
mode
==
"WXYZ"
:
if
self
.
mode
==
"WXYZ"
:
if
self
.
normalize
:
quaternionList
=
[
q
.
normalized
()
for
q
in
quaternionList
]
for
i
,
name
in
enumerate
(
"WXYZ"
):
for
i
,
name
in
enumerate
(
"WXYZ"
):
if
outputs
[
name
].
is_linked
:
if
outputs
[
name
].
is_linked
:
outputs
[
name
].
sv_set
([[
q
[
i
]
for
q
in
quaternionList
]])
outputs
[
name
].
sv_set
([[
q
[
i
]
for
q
in
quaternionList
]])
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать