iconEuler Examples

Geometry with Euler

This notebook demonstrates analytic geometry in Euler, numerically
in the Euler matrix language, and in symbolic form using Maxima.

The geometry functions are in an Euler file geometry.e.
>load geometry
This file contains functions for analytic geometry in the plane. There
are numerical Euler functions, and symbolic Maxima functions. 

Example

We set the range for our plot. The plots of geometry objects all
hold the old plot and add the objects to it.
>setPlotRange(-0.5,2.5,-0.5,2.5);
Now set three points and plot them.
>A=[1,0]; plotPoint(A,"A");
>B=[0,1]; plotPoint(B,"B");
>C=[2,2]; plotPoint(C,"C");
Then three segments.
>plotSegment(A,B,"c");
>plotSegment(B,C,"a");
>plotSegment(C,A,"b");
The geometry functions include functions to create lines and circles.
The format for the line is [a,b,c], which represents the line
with equation ax+by=c.
>lineThrough(B,C)
[ -1  2  2 ]
Compute the perpendicular line through A on BC.
>ha=perpendicular(A,lineThrough(B,C));
And its intersection with BC.
>H=lineIntersection(ha,lineThrough(B,C));
Plot that.
>plotPoint(H,value=1);
>plotSegment(A,H); insimg;

Geometry Examples

Compute the are of ABC.
>norm(A-H)*norm(B-C)/2
1.5
Compare with determinant formula.
>areaTriangle(A,B,C)
1.5
The length of the height.
>distance(A,H)
1.3416407865
The angle at C.
>degprint(computeAngle(B,C,A))
36°52'11.63''
Now the circumcircle of the triangle.
>c=circleThrough(A,B,C); getCircleRadius(c)
1.17851130198
>plotPoint(getCircleCenter(c),"U");
>plotCircle(c,"Circumcircle"); insimg;

Geometry Examples

This the midpoint of the circle.
>fracformat; getCircleCenter(c), longformat;
[ 7/6  7/6 ]
>l=angleBisector(A,C,B); g=angleBisector(C,A,B);
>I=lineIntersection(l,g)
[ 0.860379610028  0.860379610028 ]
>color(5); plotLine(l); plotLine(g); color(1);
>plotPoint(I,"I");
>plotCircle(circleWithCenter(I,norm(I-projectToLine(I,lineThrough(A,B)))));
>insimg;

Geometry Examples

Example for symbolic Geometry

We can compute exact and symbolic geometry using Maxima.

The file geometry.e provides the same (and more) functions in
Maxima. However, we can use symbolic computations now.
>mxmset(A); mxmset(B); mxmset(C);
The functions for lines and circle work just like the Euler functions,
but provide symbolic computations.
>:: c := lineThrough(B,C)

part: invalid index of list or matrix.
#0: turnLeft(v=matrix([2,1]))
#1: lineThrough(a=matrix([0,1]),b=matrix([2,2]))
 -- an error. To debug this try: debugmode(true);

We can get the equation for a line easily.
>:: getLineEquation(c,x,y), solve(%,y) | expand
                           c  y + c  x = c
                            2      1      3


                                c    c  x
                                 3    1
                           [y = -- - ----]
                                c     c
                                 2     2

>:: getLineEquation(lineThrough(A,[x1,y1]),x,y)

fullmap: arguments must have same formal structure.
#0: lineThrough(a=matrix([1,0]),b=[x1,y1])
 -- an error. To debug this try: debugmode(true);

>:: ha := perpendicular(A,lineThrough(B,C))

part: invalid index of list or matrix.
#0: turnLeft(v=matrix([2,1]))
#1: lineThrough(a=matrix([0,1]),b=matrix([2,2]))
 -- an error. To debug this try: debugmode(true);

>:: H := lineIntersection(c,ha)
                    ha  c  - c  ha   ha  c  - c  ha
                      2  3    2   3    1  3    1   3
                 [- ---------------, ---------------]
                    ha  c  - c  ha   ha  c  - c  ha
                      1  2    1   2    1  2    1   2

>:: projectToLine(A,lineThrough(B,C))

part: invalid index of list or matrix.
#0: turnLeft(v=matrix([2,1]))
#1: lineThrough(a=matrix([0,1]),b=matrix([2,2]))
 -- an error. To debug this try: debugmode(true);

>:: distance(A,H), % | float

fullmap: arguments must have same formal structure.
#0: distance(a=matrix([1,0]),b=[-(ha[2]*c[3]-c[2]*ha[3])/(ha[1]*c[2]-c[1]*ha[2]),(ha[1]*c[3]-c[1]*ha[3])/(ha[1]*c[2]-c[1]*ha[2])])
 -- an error. To debug this try: debugmode(true);


                    ha  c  - c  ha   ha  c  - c  ha
                      2  3    2   3    1  3    1   3
                 [- ---------------, ---------------]
                    ha  c  - c  ha   ha  c  - c  ha
                      1  2    1   2    1  2    1   2

>:: cc := circleThrough(A,B,C)

part: invalid index of list or matrix.
#0: turnLeft(v=matrix([-1,1]))
#1: middlePerpendicular(a=matrix([1,0]),b=matrix([0,1]))
#2: circleThrough(a=matrix([1,0]),b=matrix([0,1]),c=matrix([2,2]))
 -- an error. To debug this try: debugmode(true);

>:: getCircleRadius(cc) | float
                                 cc
                                   3

>:: computeAngle(A,C,B)
                                    4
                               acos(-)
                                    5

>:: solve(getLineEquation(angleBisector(A,C,B),x,y),y)[1]

part: invalid index of list or matrix.
#0: turnLeft(v=matrix([-1,1]))
#1: middlePerpendicular(a=matrix([1,0]),b=matrix([0,1]))
#2: angleBisector(a=matrix([1,0]),b=matrix([2,2]),c=matrix([0,1]))
 -- an error. To debug this try: debugmode(true);

>:: I := lineIntersection(angleBisector(A,C,B),angleBisector(C,B,A))

part: invalid index of list or matrix.
#0: turnLeft(v=matrix([-1,1]))
#1: middlePerpendicular(a=matrix([1,0]),b=matrix([0,1]))
#2: angleBisector(a=matrix([1,0]),b=matrix([2,2]),c=matrix([0,1]))
 -- an error. To debug this try: debugmode(true);

>mxmeval("I")
[ 0.860379610028  0.860379610028 ]

Intersecting Lines and Circles

Of course, we can also intersect lines with circles, and circles
with circles.
>A=[1,0]; c=circleWithCenter(A,4); B=[1,2]; C=[2,1]; l=lineThrough(B,C);
>setPlotRange(5); plotCircle(c); plotLine(l);
The intersection of a line with a circle returns two points and
the number of intersection points.
>{P1,P2,f}=lineCircleIntersections(l,c);
>P1, P2,
[ 4.64575131106  -1.64575131106 ]
[ -0.645751311065  3.64575131106 ]
>plotPoint(P1); plotPoint(P2); insimg;

Geometry Examples

The same in Maxima.
>mxmset(A); mxmset(B); mxmset(C);
>:: c := circleWithCenter(A,4)

part: invalid index of list or matrix.
#0: circleWithCenter(a=matrix([1,0]),r=4)
 -- an error. To debug this try: debugmode(true);

>:: l := lineThrough(B,C)

part: invalid index of list or matrix.
#0: turnLeft(v=matrix([1,-1]))
#1: lineThrough(a=matrix([1,2]),b=matrix([2,1]))
 -- an error. To debug this try: debugmode(true);

>:: lineCircleIntersections(l,c) | radcan, % | float
                      2                              2    2   2
        [[(l  sqrt(- l  + (2 c  l  + 2 c  l ) l  + (l  + l ) c
            2         3       2  2      1  1   3     2    1   3
    2  2                    2  2                2
 - c  l  - 2 c  l  c  l  - c  l ) + l  l  + c  l  - l  c  l )
    2  2      1  1  2  2    1  1     1  3    1  2    1  2  2
   2    2                 2                              2    2   2
/(l  + l ), - (l  sqrt(- l  + (2 c  l  + 2 c  l ) l  + (l  + l ) c
   2    1       1         3       2  2      1  1   3     2    1   3
    2  2                    2  2                        2
 - c  l  - 2 c  l  c  l  - c  l ) - l  l  + c  l  l  - l  c )
    2  2      1  1  2  2    1  1     2  3    1  1  2    1  2
   2    2                   2                              2    2   2
/(l  + l )], [- (l  sqrt(- l  + (2 c  l  + 2 c  l ) l  + (l  + l ) c
   2    1         2         3       2  2      1  1   3     2    1   3
    2  2                    2  2                2
 - c  l  - 2 c  l  c  l  - c  l ) - l  l  - c  l  + l  c  l )
    2  2      1  1  2  2    1  1     1  3    1  2    1  2  2
   2    2               2                              2    2   2
/(l  + l ), (l  sqrt(- l  + (2 c  l  + 2 c  l ) l  + (l  + l ) c
   2    1     1         3       2  2      1  1   3     2    1   3
    2  2                    2  2                        2
 - c  l  - 2 c  l  c  l  - c  l ) + l  l  - c  l  l  + l  c )
    2  2      1  1  2  2    1  1     2  3    1  1  2    1  2
   2    2
/(l  + l )]]
   2    1


                      2                              2    2   2
        [[(l  expt(- l  + (2 c  l  + 2 c  l ) l  + (l  + l ) c
            2         3       2  2      1  1   3     2    1   3
    2  2                    2  2                     2
 - c  l  - 2 c  l  c  l  - c  l , 0.5) + l  l  + c  l  - l  c  l )
    2  2      1  1  2  2    1  1          1  3    1  2    1  2  2
   2    2                 2                              2    2   2
/(l  + l ), - (l  expt(- l  + (2 c  l  + 2 c  l ) l  + (l  + l ) c
   2    1       1         3       2  2      1  1   3     2    1   3
    2  2                    2  2                             2
 - c  l  - 2 c  l  c  l  - c  l , 0.5) - l  l  + c  l  l  - l  c )
    2  2      1  1  2  2    1  1          2  3    1  1  2    1  2
   2    2                   2                              2    2   2
/(l  + l )], [- (l  expt(- l  + (2 c  l  + 2 c  l ) l  + (l  + l ) c
   2    1         2         3       2  2      1  1   3     2    1   3
    2  2                    2  2                     2
 - c  l  - 2 c  l  c  l  - c  l , 0.5) - l  l  - c  l  + l  c  l )
    2  2      1  1  2  2    1  1          1  3    1  2    1  2  2
   2    2               2                              2    2   2
/(l  + l ), (l  expt(- l  + (2 c  l  + 2 c  l ) l  + (l  + l ) c
   2    1     1         3       2  2      1  1   3     2    1   3
    2  2                    2  2                             2
 - c  l  - 2 c  l  c  l  - c  l , 0.5) + l  l  - c  l  l  + l  c )
    2  2      1  1  2  2    1  1          2  3    1  1  2    1  2
   2    2
/(l  + l )]]
   2    1

Now we check the chord angle theorem.
>C=A+normalize([-2,-3])*4; plotPoint(C); plotSegment(P1,C); plotSegment(P2,C);
>computeAngle(P1,C,P2)
1.20942920289
>C=A+normalize([-4,-3])*4; plotPoint(C); plotSegment(P1,C); plotSegment(P2,C);
>computeAngle(P1,C,P2)
1.20942920289
>insimg;

Geometry Examples

The Middle Perpendicular

Let us construct the middle perpendicular the usual way.
>A=[2,2]; B=[-1,-2];
>c1=circleWithCenter(A,distance(A,B));
>c2=circleWithCenter(B,distance(A,B));
>{P1,P2,f}=circleCircleIntersections(c1,c2);
>l=lineThrough(P1,P2);
>setPlotRange(5); plotCircle(c1); plotCircle(c2);
>plotPoint(A); plotPoint(B); plotLine(l); insimg;

Geometry Examples

Next, we do the same in Maxima with general coordinates.
>:: A:=[a1,a2]; B:=[b1,b2];
>:: c1 := circleWithCenter(A,distance(A,B));
>:: c2 := circleWithCenter(B,distance(A,B));
>:: is := circleCircleIntersections(c1,c2); P1:=is[1]; P2:=is[2];
The equations for the intersections are quite involved. But we
can simplify, if we solve for y.
>:: solve(getLineEquation(lineThrough(P1,P2),x,y),y)
                                      2     2     2     2
                  (2 b1 - 2 a1) x - b2  - b1  + a2  + a1
           [y = - ---------------------------------------]
                                2 b2 - 2 a2

This is indeed the same as the middle perpendicular, which is
computed in a completely different way.
>:: solve(getLineEquation(middlePerpendicular(A,B),x,y),y)
                                      2     2     2     2
                  (2 b1 - 2 a1) x - b2  - b1  + a2  + a1
           [y = - ---------------------------------------]
                                2 b2 - 2 a2

Examples Homepage