2DPGA: Points and LinesΒΆ

This example shows some basic operations on points and lines using 2DPGA.

Based on https://enkimute.github.io/ganja.js/examples/coffeeshop.html#pga2d_points_and_lines.

First we create 2DPGA, and add its basis blades to the local namespace.

[1]:
from kingdon import Algebra

alg = Algebra(2, 0, 1)
locals().update(alg.blades)

Next, make formulas to construct points and lines from coefficients. In 2D PGA, grade-1 elements or vectors (e0,e1,e2) represent reflections AND lines (the invariant of a reflection).

[2]:
line = lambda a, b, c: a*e1 + b*e2 + c*e0

Grade-2 elements or bivectors (e01,e02,e12) represent rotations/translations AND points/infinite points (the invariant of a rotation/translation). We define them using the dualisation operator (.dual()) to be independent of choice of basis (e.g. e12 vs e21).

[3]:
point = lambda x, y: (e0 + x*e1 + y*e2).dual()

Construct the points \(A\), \(B\), and \(C\).

[4]:
A = point(-1, -1)
B = point(-1, 1)
C = point(1, 1)

Define the line

\[y = 0.5 - x \implies x + y - 0.5 = 0\]
[5]:
L = line(1, 1, -0.5)

A line can also be defined by JOINING (\(\vee\)) two points. Mathematically this is done with the VEE operator \(\vee\), which in kingdon code is implemented with &. Let us create the line

\[M = C \vee A\]

Moreover, we define the line M as a function so it will update when C or A are dragged:

[6]:
M = lambda: C & A

Similarly, a point can be defined by MEETING (^) two lines. Again, we define the point D as a function so it will update when L or M change.

[7]:
D = lambda: L ^ M
[8]:
g = alg.graph(
    "Drag A,B,C",   # First label is used as title.
    0xD0FFE1,       # Numbers are colors - use hex!
    [A,B,C],        # render polygon ABC.
    0x882288,       # Set the color to purple.
    [B,C],          # Render line segment from B to C.
    0x00AA88,       # Medium green.
    L, "L", M, "M", # Render and label lines.
    0x224488,       # Set color blue.
    D, "D",         # Intersection point of L and M
    0x008844,       # Set darker green
    A, "A",         # Render point A and label it.
    B, "B",         # Render point B and label it.
    C, "C",         # Render point C and label it.
    lineWidth=3, grid=True, labels=True
)
g
[8]:
[ ]: