Skip to content

Commit

Permalink
SymPy support, and try to solve my LookAt quaternion equation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zemnmez committed Sep 28, 2024
1 parent 4365005 commit 94b5c74
Show file tree
Hide file tree
Showing 8 changed files with 1,105 additions and 13 deletions.
5 changes: 3 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"brunnerh.insert-unicode",
"ms-python.black-formatter",
"ms-python.mypy-type-checker",
"iliazeus.vscode-ansi"
"iliazeus.vscode-ansi",
"ms-toolsai.jupyter"
]
}
}
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ py_venv(
"//project/cultist/gen/testing",
"//py/hello_world:hello_world_bin",
"//py/ibazel:ibazel_bin",
"//py/ipynb:ipynb_bin",
"//py/sectxt:sectxt_bin",
],
)
88 changes: 87 additions & 1 deletion gazelle_python.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions py/ipynb/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("//bzl:rules.bzl", "bazel_lint")
load("//py:rules.bzl", "py_binary")

py_binary(
name = "ipynb_bin",
srcs = ["__main__.py"],
main = "__main__.py",
visibility = ["//:__subpackages__"],
deps = ["@pip//sympy"],
)

bazel_lint(
name = "bazel_lint",
srcs = ["BUILD.bazel"],
)
42 changes: 42 additions & 0 deletions py/ipynb/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from sympy import Quaternion, solve, symbols, Eq

centre = Quaternion(0, *symbols('c_i c_j c_k', real=True))

# vector from centre upward
up = Quaternion(0, *symbols('u_i u_j u_k', real=True))

forward = Quaternion(0, *symbols('fw_i fw_j fw_k', real=True))

r_w, r_i, r_j, r_k = symbols('r_w r_i r_j r_k', real=True)

rotation = Quaternion(r_w, r_i, r_j, r_k)

look_at = Quaternion(0, *symbols('la_i la_j la_k', real=True))

centre_does_not_rotate = Eq(centre * rotation, centre)

forward_will_look_at = Eq(
((centre - forward) * rotation).normalize(),
(centre - look_at).normalize()
)

length_of_forward_unchanged = Eq(
(forward-centre).norm(),
((forward * rotation) - centre).norm()
)

up_will_still_be_up = Eq(
(up * rotation),
up
)

solve(
[
length_of_forward_unchanged,
centre_does_not_rotate,
forward_will_look_at,
up_will_still_be_up
], [
r_w, r_i, r_j, r_k
]
)
Loading

0 comments on commit 94b5c74

Please sign in to comment.