forked from StudioInfinity/dyna3
Get Ganja.js to display planes
This commit is contained in:
parent
8eb1ebb8d2
commit
242d630cc6
2 changed files with 36 additions and 4 deletions
|
|
@ -123,12 +123,24 @@ mutable struct ConstructionViewer
|
|||
end
|
||||
end
|
||||
|
||||
mprod(v, w) =
|
||||
v[1]*w[1] + v[2]*w[2] + v[3]*w[3] + v[4]*w[4] - v[5]*w[5]
|
||||
|
||||
function display!(viewer::ConstructionViewer, elements::Matrix)
|
||||
# load elements
|
||||
elements_full = [
|
||||
[0; elt; fill(0, 26)]
|
||||
for elt in eachcol(elements)
|
||||
]
|
||||
elements_full = []
|
||||
for elt in eachcol(elements)
|
||||
if mprod(elt, elt) < 0.5
|
||||
elt_full = [0; elt; fill(0, 26)]
|
||||
else
|
||||
# `elt` is a spacelike vector, representing a generalized sphere, so we
|
||||
# take its Hodge dual before passing it to Ganja.js. the dual represents
|
||||
# the same generalized sphere, but Ganja.js only displays planes when
|
||||
# they're represented by vectors in grade 4 rather than grade 1
|
||||
elt_full = [fill(0, 26); -elt[5]; -elt[4]; elt[3]; -elt[2]; elt[1]; 0]
|
||||
end
|
||||
push!(elements_full, elt_full)
|
||||
end
|
||||
@js viewer.win elements = $elements_full.map((elt) -> @new CGA3(elt))
|
||||
|
||||
# generate palette. this is Gadfly's `default_discrete_colors` palette,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue