clifford

repository·master·Indexed 21 days ago

https://github.com/pygae/clifford

A numerical Geometric Algebra (Clifford algebra) package for Python that allows for the seamless mixing of scalars, vectors, and higher-grade entities as multivectors. It provides tools for defining algebraic structures via Cl(), managing multivectors with the MultiVector class, and performing operations like 3D rotations using rotors. The library includes predefined algebras such as g2, g3, and pga, as well as utilities like conformalize() for mapping to Conformal Geometric Algebra.

Tokens
19.5K
Snippets
84
Records
97
Agent score
75%

What's inside clifford

  1. Overview of Clifford Algebra capabilities

    master

    The clifford module implements Geometric Algebras (Clifford algebras). It is a universal algebra that subsumes several mathematical systems, including:

    • Complex algebra
    • Quaternions
    • Linear algebra

    In this library, scalars, vectors, and higher-grade entities can be mixed freely and consistently in the form of mixed-grade multivectors.

  2. Data type and storage considerations

    master

    The clifford module does not prioritize preserving array dtype or optimizing storage.

    • Storage: If your application requires massive numbers of multivectors where memory footprint is critical, the current class structure is not suitable. You should implement application-specific data structures using the algorithms provided in this module.
    • Integer Division: MultiVectors will have integer coefficients if instantiated that way. Dividing them by Python integers follows standard Python integer division rules.
  3. Quickstart: Perform 3D rotations with Geometric Algebra

    master

    To use Geometric Algebra for 3D space, import from clifford.g3. You can define vectors using basis vectors (e.g., e1, e2, e3) and perform rotations using rotors. A rotor $R$ can rotate a vector $a$ using the sandwich product $R a \tilde{R}$, where ~ denotes the reverse of the multivector.

    from clifford.g3 import *  # import GA for 3D space
    from math import e, pi
    
    a = e1 + 2*e2 + 3*e3 # vector 
    R = e**(pi/4*e12)    # rotor 
    R*a*~R              # rotate the vector
  4. Quickstart with Geometric Algebra in 3D space

    master

    To begin using Geometric Algebra for 3D space, import the g3 module from clifford. This provides the basis vectors e1, e2, and e3. You can then create vectors, rotors, and perform geometric operations like rotations using multivector arithmetic.

    Key concepts:

    • Basis Vectors: e1, e2, e3 represent the orthogonal axes.
    • Rotors: Created using the exponential of a bivector (e.g., math.e**(math.pi/4*e12)).
    • Sandwich Product: Rotating a vector a with a rotor R is performed via R * a * ~R, where ~R is the inverse of the rotor.
    from clifford.g3 import *
    import math
    
    a = e1 + 2*e2 + 3*e3  # vector
    R = math.e**(math.pi/4*e12)  # rotor
    
    # rotate the vector
    result = R * a * ~R
    # Output: (2.0^e1) - (1.0^e2) + (3.0^e3)
  5. Learn Clifford via slide decks and videos

    master

    You can supplement your use of the clifford library with the following educational resources:

    Slide Decks

    • Installation: Guide for installing Python and clifford.
    • Conformal Geometric Algebra with Python (Part 1 & 2): Deep dives into using the library for Conformal Geometric Algebra (CGA).

    Videos

    • Intro to Clifford: A video introduction to the library and its concepts.
  6. Visualize geometric objects with mpl_toolkits.clifford

    master

    mpl_toolkits.clifford integrates with matplotlib, allowing you to use standard plotting workflows. This is useful when you need to combine geometric visualizations with other scientific plots.

    Key usage details:

    • Plotting: Use plot(ax, [list_of_objects], ...) where ax is a matplotlib Axes object.
    • 2D Visualization: Use standard plt.subplots().
    • 3D Visualization: Use plt.subplots(..., subplot_kw=dict(projection='3d')).
    • Styling: Supports standard matplotlib arguments like color, label, marker, linestyle, linewidth, and markeredgewidth.
    • Limitations: Labels do not work for spheres in mpl_toolkits.clifford.
    • Tip: Due to floating point rounding errors in clifford.tools.classify, you may need to call .normal() on objects to ensure they render correctly.
    from matplotlib import pyplot as plt
    from mpl_toolkits.clifford import plot
    
    fig, ax = plt.subplots()
    plot(ax, [point, line, circle], color='tab:blue', label='objects')
    plt.show()
  7. Use predefined algebras for faster startup

    master

    Instead of manually constructing a Clifford algebra using clifford.Cl, you can use predefined algebra modules. These modules are optimized for faster startup and provide convenient access to basis blades and layout information.

    Available predefined algebras include:

    • clifford.g2: 2D Euclidean, Cl(2)
    • clifford.g3: 3D Euclidean, Cl(3)
    • clifford.g4: 4D Euclidean, Cl(4)
    • clifford.g2c: Conformal space for G2, Cl(3, 1)
    • clifford.g3c: Conformal space for G3, Cl(4, 1)
    • clifford.pga: Projective space for G3, Cl(3, 0, 1)
    • clifford.pga2d: Projective space for G2, Cl(2, 0, 1)
    • clifford.gac: Geometric Algebra for Conics, Cl(5, 3)
    • clifford.dpga: Double PGA (Mother Algebra), Cl(4, 4)
    • clifford.dg3c: Double Conformal Geometric Algebra, Cl(8, 2)
    from clifford import g2
    
    # Access basis blades directly from the module
    blade = g2.e1 * g2.e2
  8. Install visualization tools for clifford

    master

    You can install the two primary visualization tools for clifford using pip:

    • pyganja: A Python interface to the ganja.js library.
    • mpl_toolkits.clifford: A toolkit for visualizing geometric objects within matplotlib.
    pip install pyganja
    pip install mpl_toolkits.clifford
  9. Explore Geometric Algebra learning resources

    master

    For a deeper theoretical understanding of Geometric Algebra beyond the clifford library, consider these resources:

    Websites

    • galgebra: A symbolic geometric algebra module for Python.
    • The Cambridge University Geometric Algebra Research Group: Academic research home page.
    • Geometric Calculus R & D Home Page: David Hestenes' research site.

    Introductory Textbooks

    • Geometric Algebra for Physicists by Doran and Lasenby.
    • Geometric Algebra for Computer Science by Dorst, Fontijne, and Mann.
    • New Foundations for Classical Mechanics by David Hestenes.