3DPGA: Points and linesΒΆ

Based on https://enki.ws/ganja.js/examples/coffeeshop.html#pga3d_points_and_lines.

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

[1]:
from kingdon import Algebra

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

Next, make formulas to construct points and planes from coefficients.

[2]:
# Construct points and lines from coefficients
point = lambda x, y, z: (e0 + x*e1 + y*e2 + z*e3).dual()
plane = lambda a, b, c, d: a*e1 + b*e2 + c*e3 + d*e0

Lets define some points to demonstrate basic incidence and rendering.

[3]:
A = point(0,.8,0)
B = point(.8,-1,-.8)
C = point(-.8,-1,-.8)
D = point(.8,-1,.8)
E = point(-.8,-1,.8)
[4]:
def graph_func():
    # Points can be joined into lines and planes
    ec = E & C
    p = A & B & C

    # Sum points to get the average position.
    avg = A + B + E
    bc = B + C

    # Join (&) points into lines
    l = avg & bc

    # Intersect a line and a plane into a point.
    intersect = l ^ (A & E & D)

    # Sum lines to get average lines.
    l2 = l.normalized() + ec.normalized()

    return [
        0xD0FFE1, [A,B,D],                                           # polygons
        0x00AA88, [A,B],[A,C],[A,D],[A,E],[B,C],[C,E],[E,D],[D,B],   # edges
        0x224488, A,"A",B,"B",C,"C",D,"D",E,"E",                     # points
        0x884488, ec,"E&C", p*0.1,"A&B&C",                           # join of points
        0x884488, bc, "B+C", avg, "A+B+E", l,                        # sum of points
        0x00AA88, intersect, "line ^ plane",                         # meets
        0xFF8844, l2, "sum of lines",                                # sum of lines.
    ]

alg.graph(
    graph_func,
    lineWidth=3,
    grid=1,
    labels=1,
    h=0.6,
    p=-0.15,
    pointRadius=1,
    fontSize=1,
    scale=1,
)
[4]:
[ ]: