biVector forum

Implementing PGA with galgebra

Hi,

I implement PGA with galgebra. First steps are promising, I’m able to wedge and vee for building points, lines and planes.

Now I try to validate the side of my planes.

If I define Px=(1,0,0), Py=(0,1,0) and Pz=(0,0,1), then J(J(Px) \wedge J(Py) \wedge J(Pz)), the result plane is d-a-b-c=0. I was hoping to get a+b+c-d=0.

Ganja.js/coffeeshop says the same thing :
// Create a Clifford Algebra with 3,0,1 metric.
Algebra(3,0,1,()=>{

    // We work in dual space. Our 1-blade's are dual-vectors (aka functionals of the form ax + by + cz + dw = 0).
    // The four basis functionals are thus (x=0, y=0, z=0, w=0). In three dimensions these represent the yz, xz, xy and
    // ideal plane. 
    
    // Specify a point directly (trivectors specified with overloaded e-notation.)
    var point = (x,y,z)=>1e123-x*1e023+y*1e013-z*1e012;

    // Planes can be defined directly using e0,e1,e2,e3
    var plane = (a,b,c,d)=>d*1e0+a*1e1+b*1e2+c*1e3;
    
    var H=point(0,-1,0), X=point(1,0,0), Y=point(0,1,0), Z=point(0,0,1),
        camera=0e0;
        
    var p = X&Y&Z;
    
    var print_p = (p)=>"d*"+p[1].toFixed(2) + " + a*" + p[2].toFixed(2) + " + b*" + p[3].toFixed(2) + " + c*" + p[4].toFixed(2)
    
    // Graph the 3D items
    document.body.appendChild(this.graph(()=>{
      var time=performance.now()/4000;    
      camera.set(Math.cos(time)+Math.sin(time)*1e13);                      // rotate around Y 
      return [0x444444,H,print_p(p),X,"X",Y,"Y",Z,"Z",                      // graph all vertices
             0xffcccc,[X,Y,Z]];
    },{animate:true,camera})); 
});

I’m missing something. Any idea ?

Regards

Your problem is that you are confusing the regressive product and the exterior product.

In Grassmann.jl you would state your problem like this:

julia> using Grassmann; @basis D"1,1,1,0"
(⟨1,1,1,0⟩, v, v₁, v₂, v₃, v₄, v₁₂, v₁₃, v₁₄, v₂₃, v₂₄, v₃₄, v₁₂₃, v₁₂₄, v₁₃₄, v₂₃₄, v₁₂₃₄)

julia> point(x,y,z) = v123 - x*v234 + y*v134 - z*v124;

julia> X,Y,Z = point(1,0,0), point(0,1,0), point(0,0,1)
(1v₁₂₃ + 0v₁₂₄ + 0v₁₃₄ - 1v₂₃₄, 1v₁₂₃ + 0v₁₂₄ + 1v₁₃₄ + 0v₂₃₄, 1v₁₂₃ - 1v₁₂₄ + 0v₁₃₄ + 0v₂₃₄)

julia> X∨Y∨Z
0 + 1v₁ + 1v₂ + 1v₃ - 1v₄

julia> !((!X)∧(!Y)∧(!Z))
0 - 1v₁ - 1v₂ - 1v₃ + 1v₄

As you can see, X∨Y∨Z ≠ !((!X)∧(!Y)∧(!Z)) because the regressive product is not computed the way you think it is computed. The last operation in the regressive product is actually to take the inverse of the complement operation and not the complement itself.

\star (X\vee Y\vee Z) = (\star X)\wedge(\star Y)\wedge(\star Z) \iff X\vee Y\vee Z = \star^{-1}((\star X)\wedge(\star Y)\wedge(\star Z))

When you correctly use the inverse of the complement, then you can compute the regressive product.

So what you are missing is the concept of an inverse for the complement or J^{-1} if you will…

Thanks !

After reading @cgunn3 thesis I was hoping J = J^{-1}, in fact he says J^2=id. I can’t see any dual inverse in @enki ganja.js too.

Maybe I need to pick @enki 's basis for avoiding to use J^{-1}. Any thought about this ?

You can’t avoid the usage of the inverse complement if you want to do the math correctly.

I don’t have a separate method for it, but it is built into my regressive product, only place it’s used.

@meuns Can you post the PGA code with galgebra so we can reproduce the issue?

@utensil you can look at https://github.com/meuns/galgebra/blob/master/tests/test_pga.py, I implemented J^{-1} and it “works”. I want to replace every Jinv by J like @enki et @cgunn3.

1 Like

The two planes you had are the same though no? d - a - b - c = 0 and a + b + c - d = 0 both represent the same plane.

The positive side of a plane is facing its normal. The second plane normal is flipped.

@meuns: Did the discussion about J and J^{-1} (including the corrections to my thesis) on the other thread fix the problem discussed here with the orientation of the plane?

Yes I implemented the whole package including the custom basis blades and the new J and J^{-1} and everything work.

1 Like

@meuns Nice! Just read the code.

Would you like to merge the code (among other exercises) into GAlgebra or you’re simply using the old GAlgebra code base as the base of your personal experiments?

I noticed that you have also added some enhancements to GAlgebra. Would you like to come join in maintaining https://github.com/pygae/galgebra ?

@utensil I will merge pygea/galgebra soon and cleanup the whole mess. I want to use the maintained version. I still need to understand PGA better first. I’m not sure J and J^{-1} are useful outside of implementing PGA. Maybe I will derive a class from Ga, maybe add a module dedicated to PGA, don’t know yet.

My free time will be very sparse now and I can’t promise anything nor maintain galgebra.

1 Like

J appears much closer to how you would implement the Hodge Star operator. https://en.wikipedia.org/wiki/Hodge_star_operator. Which is used extensively in Exterior Calculus. You could use parts of a GA library as a starting point for an Exterior Calculus implementation, since they both use Grassmann’s Exterior Algebra ( wedge product ).

Why do this if you are mainly interested in GA/C?
It’s interesting to see the similarities and differences between Exterior Calculus and Geometric Calculus.
Easier to convert an existing DEC algorithm into a Geometric Calculus version.

So J, Hodge star and Reciprocal Frames seem to be related. https://galgebra.readthedocs.io/en/latest/galgebra_guide.html#Reciprocal-Frames
I’m still learning Geometric Calculus. What would Reciprocal Frames look like with a degenerate metric?

I don’t think this is accurate because the Hodge Star operator requires a non-degenerate metric to be well-defined. The wiki defines the Hodge dual of \beta to be a \beta^\star such that

\alpha \wedge \beta^\star = \langle \alpha, \beta \rangle w

Where w is a unit-vector unique up to a sign.

For projective GA, in particular, such a definition just isn’t very useful.

Is there any practical application of exterior calculus in animation or rendering?

You are incorrect, the Hodge definition should always be the default for geometric algebra. The metric independent definition is what you are referring to, but metric independent complement is definitely not the natural definition that falls out from the geometric product foundation in the theory. However, the Hodge dual is definitely the correct default complement.

That is not to say that the metric independent complement does not have usefulness, but it definitely is not the more natural one of the two complements, because it requires a modification of the geometric product to define, unlike the Hodge complement.

Hodge complement is the most simple and natural definition of complement you could make, directly based on the reversed geometric product. The metric independent variant is less natural, and requires a modification of the geometric product without metric, and is thus less natural in terms of geometric algebra.

You might say that metric independent geometric product is more natural, but what is the default for geometric products? With metric or without? Clearly, the default in geometric algebra is to do the geometric product with metric, making Hodge more natural.

Ultimately, you should definitely have both if you are really serious about the math though. However, if you don’t yet see how Hodge definition is more natural yet, then you have not yet understood the foundation of the complement in terms of the geometric product… because the geometric product is the most foundational and natural definition used in all of geometric algebra… in my paper I showed how you basically get the entire theory from just the geometric product and Hodge complement. The metric independent variant is not as natural, but also useful.

In Grassmann algebra, the metric independent variant might be the more natural, if you never assume actually assume a metric, but geometric algebra does usually assume the metric and the geometric product.

  • Grassmann: metric independent is more natural
  • Geometric algrbra: Hodge dual is more natural

This is because in Grassmann algebra you can work without metric, but in geometric algebra, a metric is assumed. Thus, Hodge is more natural for GA, while metric independent is natural for Grassmann exterior algebra before assuming a metric… however, I really see the metric independent complement as a modification of the simpler defined Hodge complement, since it really is a modification of it.

Sorry but your post makes no sense to me, probably because you are misreading mine. First, note the distinction between “not having a metric” and “having a degenerate metric.” Your post seems to conflate the two, whereas I was specifically talking about the hodge dual in the context of the latter. Second, I never mentioned the what should or shouldn’t be the default. I was speaking specifically to the comparison drawn between the Hodge dual and J. Last, … J requires modifying the geometric product? No idea what you are referring to here.

The modified definition of complement is metric independendent (does not depend on metric), presumably you want a non-degenerate complement when you are using the degenerate metric. Hence, you want to use a metric independent complement. Therefore, I am not incorrectly conflating it.

Your actual claim is:

You are saying that in geometric algebra, the Hodge complement is not very useful.

What I tried to explain to you in my post is that the Hodge complement is actually very fundamental for geometric algebra in general, while you are claiming that it is not useful for GA. This is plainly wrong, as the Hodge complement is the most natural and easy definition for complement you can get. The other variant of complement is in fact less natural to the theory, since it isn’t based on the geometric product unlike the Hodge complement.

So, I’m just responding to your claim that the Hodge complement isn’t useful, when in fact it is very useful… as the Hodge complement can be used in projective GA, which does not use a degenerate metric anyway (also, null basis does not actually use a degenerate metric).

? Note the subforum you’re in.