Skip to content

Instantly share code, notes, and snippets.

@alok
Created May 4, 2024 08:39
Show Gist options
  • Save alok/698fad03a0e1e95f6e678d512af93f60 to your computer and use it in GitHub Desktop.
Save alok/698fad03a0e1e95f6e678d512af93f60 to your computer and use it in GitHub Desktop.
5 and 17 dimensional rotations
# Reorganized code to focus on rotating a random 17-dimensional multivector and projecting it to 3D for visualization
using Grassmann
# Define the basis for 3D and 17D spaces
basis_3,basis_5,basis_17 = Λ(3), Λ(5), Λ(17)
# Define submanifolds for 3D and 17D spaces
V_3, V_5, V_17 = Submanifold(3), Submanifold(5), Submanifold(17)
function random_mv(n)
return rand(Spinor{Submanifold(n), Float64})
end
random_mv(5)
project(random_mv(5), basis_3.v1+basis_3.v2+basis_3.v3)
# Generate a random 17-dimensional Spinor
rand_mv = rand(Spinor{V_5, Float64})
# Define a plane in 5D for rotation
plane = basis_5.v12
# Function to rotate a multivector in a given plane by a specified angle
function rotate(mv, plane, angle)
# Using exponential map for rotation
return exp(-angle / 2 * plane) * mv * exp(angle / 2 * plane)
end
# Example usage: Rotate the random multivector in the defined plane by π/4 radians
rotated_mv = rotate(rand_mv, plane, π/4)
# projection_mv = Projector(basis_3.v1+basis_3.v2)
# Function to project a multivector onto another multivector
function project(mv, onto_mv)
return (mv ⋅ onto_mv) * onto_mv^-1
end
function project_to_3d(mv,n)
basis = Λ(n)
return project(mv, basis.v1+basis.v2+basis.v3)
end
# Example usage: Project the rotated multivector to 3D for visualization
projected_3d_mv = project_to_3d(rotated_mv,5)
rotated_mv
project(rotated_mv, basis_5.v1+basis_5.v2+basis_5.v3)
# acts as direct sum giving
sum(basis_5)
project(rotated_mv, sum(basis_5))
function main(n)
mv = random_mv(5)
rotated_mv = rotate(mv, plane, π/4)
projected_3d_mv = project_to_3d(rotated_mv,5)
return projected_3d_mv
end
main(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment