kill(all)$

programming :maxima :geometry , version 1.0a,update code.
peter.vlasschaert@gmail.com,26/11/2020

see : The Euler line of a triangle
========================
-----------------------------------------------------------------------------------------------------
=>  https://andrejv.wordpress.com/2010/01/11/the-euler-line-of-a-triangle/
update : with graphics, definitions from website
------------------------------------------------------------------------------------------------------

How to use : Definition =Def
======================

line : A =[x1,y1], B=[x2,y2] , use two points.

→ Def1

line_A_B(A, B) :=
   block([k, n],
      k: (A[2]-B[2])/(A[1]-B[1]),
      n: A[2]-k*A[1],
      k*x+n)$

y1a:line_A_B([1,1], [3,2]);
wxplot2d(%,[x,-5,5]);

local :variables, see block function.

k;
n;

A=[x1,y1] , line : l = m*x+n, 'x variable',perpendicular.'k'

→Def2

line_A_l(A,l) :=
   block([k,n],
      k: -1/coeff(l, x),
      n: A[2]-k*A[1],
      k*x+n)$

see:https://stackoverflow.com/questions/7306784/maxima-2d-plot-how-to-set-axes-equal

y2a:line_A_l([1,1],y1a);
wxplot2d([y1a,y2a],[x,-5,5],[y,-5,5],[same_xy],grid2d);

How to find : intersection  (red line,blue line) =[xi,yi]

→Def3

line_intersection(l1, l2) :=
   block(
      [sol:solve(l1=l2, x)],
      ratsimp(subst(sol, [x, l1])))$

grind(line_intersection)$

[xi,yi]:line_intersection(y1a, y2a);

[xi,yi]; /* see figure :above */

check : intersection(y1,y2)
--------------------------------------

pa:y1a;
pb:y2a;

find : xi
----------
y1a = y2a

paa:solve(pa=pb,x);

find:yi
--------

pc1:subst(%,pb);
pc2:subst(paa,pb);

check point  A  is on the line l
----------------------------------------

→Def4

point_on_line(A, l) :=
   is(equal(subst(map("=", [x,y], A), y-l),0))$

two times true :[1,1] ?
why : because is the point of intersection(y1,y2) =[xi,yi]
result  : [xi,yi] both y1 & y2

point_on_line([xi,yi], y1a);
point_on_line([xi,yi], y2a);

see: website
Centroid,Circumcenter,Orthocenter => Euler line

three points : triangle
================

P1: [x1, y1]$
P2: [x2, y2]$
P3: [x3, y3]$

Centroid (Ce,blue)
=======

M1: (P2+P3)/2$
M2: (P1+P3)/2$
M3: (P1+P2)/2$

How compute the medians:
--------------------------------------
m1→ [(x3+x2+x1)/3,(y3+y2+y1)/3]
m2→ [(x3+x2+x1)/3,(y3+y2+y1)/3]
m3→ [(x3+x2+x1)/3,(y3+y2+y1)/3]

m1: line_A_B(P1, M1)$
m2: line_A_B(P2, M2)$
m3: line_A_B(P3, M3)$

→ Ce (intersection of m1 and m2)

Ce: line_intersection(m1, m2)$
Ce1:line_intersection(m1, m3)$
Ce2:line_intersection(m2, m3)$

point_on_line(Ce, m3);

Circumcenter (Ci,red)
===========
Define the perpendicular bisectors:

pb1: line_A_l(M1, line_A_B(P2, P3))$
pb2: line_A_l(M2, line_A_B(P1, P3))$
pb3: line_A_l(M3, line_A_B(P1, P2))$

Check that the intersection of pb1 and pb2 is on pb3:

Ci: line_intersection(pb1, pb2)$
point_on_line(Ci, pb2);

Orthocenter(O,green)
=========
Compute the altitudes:

a3: line_A_l(P3, line_A_B(P1,P2))$
a2: line_A_l(P2, line_A_B(P1,P3))$
a1: line_A_l(P1, line_A_B(P2,P3))$

Check that the intersection of a1 and a2 is on the line a3:

O: line_intersection(a1, a2)$

point_on_line(O, a3);

The Euler line (black)
================
use : Def 1,2,3,4

e: line_A_B(Ce, Ci)$ 

graphics
=======

→ set defaults for graphics

set_draw_defaults(proportional_axes = xy)$
wxplot_size:[400, 400]$

draw_triangle1(d1, d2, d3) :=
   block([x1,x2,x3,y1,y2,y3],
      [x1,y1]:d1,
      [x2,y2]:d2,
      [x3,y3]:d3,
      wxdraw2d(
         fill_color="white",
         line_width=2,
            polygon([d1, d2, d3]),
         line_width=1,
         color="blue"))$

draw_triangle1([1,1],[10,6],[3,10])$

draw_triangle2(d1, d2, d3) :=
   block([x1,x2,x3,y1,y2,y3],
      [x1,y1]:d1,
      [x2,y2]:d2,
      [x3,y3]:d3,
      wxdraw2d(
         fill_color="white",
         line_width=2,
            polygon([d1, d2, d3]),
         line_width=1,
         color="blue",
         xrange=[0,11],
         yrange=[0,11],
         axis_top = false,
         axis_bottom = false,
         axis_left = false,
         axis_right = false,
         ytics = false,
         xtics = false)
        )$

display : only triangle on the canvas
-------------------------------------------------

draw_triangle2([1,1],[10,6],[3,10])$

draw_triangle3(P1, P2, P3) :=
   block([x1,x2,x3,y1,y2,y3],
      [x1,y1]:P1,
      [x2,y2]:P2,
      [x3,y3]:P3,
      wxdraw2d(
         fill_color="white",
         line_width=2,
            polygon([P1,P2,P3]),
         line_width=1,
         color="blue",
            explicit(ev(m1), x, 0, 11),
            explicit(ev(m3), x, 0, 11),
            explicit(ev(m2), x, 0, 11),        
         xrange=[0,11],
         yrange=[0,11],
         axis_top = false,
         axis_bottom = false,
         axis_left = false,
         axis_right = false,
         ytics = false,
         xtics = false      
    
    ))$
            

→ draw lines in the triangle

draw_triangle3([1,1],[10,6],[3,10])$

draw_triangle4(P1, P2, P3) :=
   block([x1,x2,x3,y1,y2,y3],
      [x1,y1]:P1,
      [x2,y2]:P2,
      [x3,y3]:P3,
      wxdraw2d(
         fill_color="white",
         line_width=2,
            polygon([P1, P2, P3]),
         line_width=1,
         color="blue",
         point_type=filled_circle,
         points_joined=true,
         point_size=0,
            explicit(ev(m1), x, 0, 11),
            explicit(ev(m2), x, 0, 11),
            explicit(ev(m3), x, 0, 11),
         point_size=1.2,
            points(ev([Ce])),
         color="red",        
         xrange=[0,11],
         yrange=[0,11],
         axis_top = false,
         axis_bottom = false,
         axis_left = false,
         axis_right = false,
         ytics = false,
         xtics = false))$

→ draw lines in the triangle & intersection point .

draw_triangle4([1,1],[10,6],[3,10])$

draw_triangle5(P1, P2, P3) :=
   block([x1,x2,x3,y1,y2,y3],
      [x1,y1]:P1,
      [x2,y2]:P2,
      [x3,y3]:P3,
      wxdraw2d(
         fill_color="white",
         line_width=2,
            polygon([P1, P2, P3]),
         line_width=1,
         color="blue",
         point_type=filled_circle,
         points_joined=true,
         point_size=0,
            explicit(ev(m1), x, 0, 11),
            explicit(ev(m2), x, 0, 11),
            explicit(ev(m3), x, 0, 11),
         point_size=1.2,
            points(ev([Ce])),
         color="red",
            points(ev([Ci])),
            explicit(ev(pb1), x, 0, 11),
            explicit(ev(pb2), x, 0, 11),
            explicit(ev(pb3), x, 0, 11),
         xrange=[0,11],
         yrange=[0,11],
         axis_top = false,
         axis_bottom = false,
         axis_left = false,
         axis_right = false,
         ytics = false,
         xtics = false))$

draw_triangle5([1,1],[10,6],[3,10])$

corrected: include the point :[0,0] as point of the triangle.

draw_triangle6(P1, P2, P3) :=
   block([x1,x2,x3,y1,y2,y3],
      [x1,y1]:P1,
      [x2,y2]:P2,
      [x3,y3]:P3,
      /* [0,0], one of the points : need this */
      if [x1,y1]=[0,0] then [x1,y1]:[0.0001,0.0001],
      if [x2,y2]=[0,0] then [x2,y2]:[0.0001,0.0001],
      if [x3,y3]=[0,0] then [x3,y3]:[0.0001,0.0001],
      wxdraw2d(
         fill_color="white",
         line_width=2,
            polygon([P1, P2, P3]),
         line_width=1,
         color="blue",
         point_type=filled_circle,
         points_joined=true,
         point_size=0,
            explicit(ev(m1), x, 0, 11),
            explicit(ev(m2), x, 0, 11),
            explicit(ev(m3), x, 0, 11),
         point_size=1.2,
            points(ev([Ce])),
         color="red",
            points(ev([Ci])),
            explicit(ev(pb1), x, 0, 11),
            explicit(ev(pb2), x, 0, 11),
            explicit(ev(pb3), x, 0, 11),
         color="dark-green",
            points(ev([O])),
            explicit(ev(a1), x, 0, 11),
            explicit(ev(a2), x, 0, 11),
            explicit(ev(a3), x, 0, 11),
         color="black",
            explicit(ev(e), x, 0, 11),
         xrange=[0,11],
         yrange=[0,11],
         axis_top = false,
         axis_bottom = false,
         axis_left = false,
         axis_right = false,
         ytics = false,
         xtics = false))$

draw_triangle6([1,1],[10,6],[3,10])$

→ :draw_triangle6([0,8],[0,0],[8,0]),get good result , corrected:draw_triangle5
corrected version : website ,euler line (=blog,see above)

draw_triangle6([0,8],[0,0],[8,0]);