Newbie Question: How to Calculate Midpoints and Parallelograms

Given 2 points in 2D or 3D PGA, how does one calculate their midpoint (it’s not in the cheat sheets)?

Related Question: Given 3 points, A, B, and C, how does one calculate the point, D such that ABCD is a parallelogram (or D’ such that ABD’C is a parallelogram, or D’’ such that AD’'BC is a parallelogram)?

I’m thinking the answers should be independent of the dimensionality of the space (and therefore the same in 2D PGA and 3D PGA). It seems the answers should be quite simple, but at this point in my self-education, I can’t figure it out.

1 Like

Hi @nwikner !

The midpoint of points A and B is simply A + B.
The point completing the parallelogram given A,B,C is simply B+C-A

See it in action here : (drag A,B,C)

code : https://enki.ws/ganja.js/examples/coffeeshop.html#sAGlDtP-1

Cheers!

1 Like

Thanks. I had tried something like that in the coffeeshop, but I guess I had a syntax error. With renewed confidence that at least my concept was correct, I was able to track it down and fix it. By the way, it’s really cool that you made the dimension a variable, and it just works when one changes 2 to 3.

Syntax errors seem to just fail silently (the page rendering simply doesn’t change and becomes static, while no error message is given), it was hard for me to know what had gone wrong. Is there some kind of debugger in the coffeeshop platform?

1 Like

yes, the javascript debugger is available. Add the statement debugger anywhere in your code, then make sure your console is open (shift+ctrl+j). You can step through the code, inspect variables by hovering and even execude code in that context from the debugger.

Cheers,

S.

1 Like

Hi @nwikner,

The answers posted are correct. However, I’d like to take the opportunity to point out some possible pitfalls that are lurking when you use the results for further calculations.

Note that most of the formulas on the cheat sheets, including the midpoint formula, assume that their arguments have been normalized, that is, X \widetilde X = \pm 1.

For a point in 2D euclidean PGA that means that it is of the form e_0 + x e_1 + y e_2, that is, the
coefficient of the e_0 term is 1. If that isn’t the case, then the point can be normalized by dividing by that coefficient. (After all, PGA is projective geometric algebra, and in projective geometry multiplying by a non-zero scalar doesn’t change the geometric primitive).

So the precise statement of the formula is that A+B is the midpoint M of A and B when A and B are normalized. Otherwise, you have to use the more cumbersome formula
M = \dfrac{A}{\|A\|} + \dfrac{B}{\| B \|},
that is obtained by normalizing the arguments before applying the formula.

The ganja demo posted on this thread creates normalized points, so you can confidently apply the formulas to these points. But when you go to feed the results to further calculations, you have to be careful.

In this example, A+B will be the desired midpoint, but it will not be normalized. If
A = e_0 + x_a e_1 + y_a e_2 and
B= e_0 + x_b e_1 + y_b e_2, then
A+B = 2 e_0 + (x_a+x_b)e_1 + (y_a+y_b) e_2.
So to normalize A+B, you have to divide by two:
M := A+B = e_0 + \dfrac{(x_a+x_b)}{2}e_1 + \dfrac{(y_a+y_b)}{2} e_2.

You should recognize the formula for the midpoint of two points here.

Using M you can find the midpoint of A+B and B:
M + B = e_0 + \dfrac{(x_a+3 x_b)}{4}e_1 + \dfrac{(y_a+3 y_b)}{4} e_2
which is the point \dfrac34 of the way from A to B, as it should be.

Without normalizing A+B, you obtain (before normalizing):
(A+B)+B = A + 2B = 3 e_0 + (x_a+2x_b)e_1 +(y_a+2 y_b) e_2
Which normalized is
e_0 + \dfrac{(x_a+2 x_b)}{3}e_1 + \dfrac{(y_a+2 y_b)}{3} e_2
which is the point \dfrac23 of the way from A to B: not correct.

I’ve extended Steven’s ganja demo to include the correct and incorrect results obtained above:
https://enkimute.github.io/ganja.js/examples/coffeeshop.html#2HKZUgmYA

The moral: always remember to normalize the results of your operations before feeding them to further calculations based on the formulas of the cheat sheets.

Thanks. I was worried about this. I guess it all worked because the formula for the completion of the parallelogram formed by the segments AB and AC, Aprime = B+C-A does (kind of accidentally) produce a normalized point if A, B, and C are normalized. Aprime = (1+1-1)e0 + (xb+xc-xa)e1 + (yb+yc-yc)e2 , so it doesn’t need to be normalized for further calculations.

BTW, a rather surprising form for the fourth corner of the parallelogram B+C-A is given by the product -BAC or if you wish -CAB.

For details see the article “Doing euclidean plane geometry using projective geometric algebra”, Sec. 5.1.

I tried it and it works. I also downloaded your article to see why it works, but that will take me longer. I have a lot of GA papers & books in my reading queue, and I am somewhat overwhelmed by the plethora of sources, the need, in many of them, to work problems in order to proceed, variations in notation, opacities in derivations, etc. Nevertheless I’m trying to persevere…