 CoCalc Public FilesAssignments / Assignment3 / MiniProject_Eulers_line.sagews
Author: Fia Su
#Mini-project: Euler's line
reset

<function reset at 0x7fc9193df050>
#Part 1

#Center of mass of a triangle
#//Imput:?
#//Output:?
def center_of_mass(z1,z2,z3):# triangle ABC: C(z3),B(z2),A(z1);format:z=a+b*I
m23=(z3+z2)/2 #Find the midpoint of AB
# Use the remark from Lecture notes to calculate the center of mass
cm=z1+(2/3)*(m23-z1)
return [cm.real(),cm.imag()]

#Example
#Triangle ABC; A(u,v),B(a,0),C(0,0)
var('u v a');assume(u,'real');assume(v,'real');assume(a,'real');

(u, v, a)
center_of_mass(u+v*I,a+0*I,0+0*I)

[1/3*a + 1/3*u, 1/3*v]
#Useful command: solving system of two linear equations
#solve?
#Example
sol=solve([2.3*x-3.*y+1.1==0.0,x+y-2.5==0.0],x,y,solution_dict=true);sol

[{y: 137/106, x: 64/53}]
[sol[x],sol[y]] #This is how you can access the solution values and make a list of these values

[64/53, 137/106]
#Useful function: line_eq(z,S) returns the lhs of the equation a*(x-x0)+b(y-y0)=0 of the line passing through a point z=x0+i*y0 and having normal [a,b]
def line_eq(z,n):
return n*(x-z.real())+n*(y-z.imag())

var('x y')

(x, y)
#Example
line_eq(3+2*I,[3,-2])

3*x - 2*y - 5
#Orthocenter
def orthocenter(z1,z2,z3): #left hand sides of eqs of two heights of the triangle
s23=z3-z2; n1=[s23.real(),s23.imag()]#encode coordinates of a normal of the height from point z1
expr1=line_eq(z1,n1) # lhs of eq of height from vertex z1
s13=z3-z1; n2=[s13.real(),s13.imag()]  #encode coordinated of a normal of the height from point z2
expr2=line_eq(z2,n2) # lhs of eq of height from vertex z2
sol=solve([expr1==0,expr2==0],x,y,solution_dict=True)  #Orthocenter coordinates
return [sol[x], sol[y]]


pt1=5+3*I;pt2=4+0*I;pt3=0+0*I

O=orthocenter(pt1,pt2,pt3);O

[5, -5/3]
#Center of circumscribed circle
def bisector_cross(z1,z2,z3):
m23=(z3+z2)/2
s23=z3-z2; n1=[s23.real(),s23.imag()] #Normal to bicector erected from the midpoint of the side connecting z3 and z2
expr1=line_eq(m23,n1)
m13=(z1+z3)/2
s13=z3-z1;n2=[s13.real(),s13.imag()]  #Normal to bicector erected from the midpoint of the side connecting z3 and z1
expr2=line_eq(m13,n2)
sol=solve([expr1==0,expr2==0],x,y,solution_dict=True)#Coordinates of the bisector intersection
return [sol[x], sol[y]]

#Part 2.
#(a) Show manually that the three special points of the triangle ABC with A=pt1, B=pt2, C=pt3,lie on a line

#C=bisector_cross(pt1,pt2,pt3);C

#M=center_of_mass(pt1,pt2,pt3);M

#H=orthocenter(pt1,pt2,pt3);H

#(b) Prove that the special points of the triangle ABC with A=u+I*v, B=a, C=0+0*I,lie on a line

var('u v a');assume(u,'real');assume(v,'real');assume(a,'real');

(u, v, a)
A=u+I*v; B=a+I*0; C=0+0*I

Find the center of mass,cm, the orthocenter,oc, and the bisector intercection,bc

cm=?
oc=?
bc=?

[1/3*a + 1/3*u, 1/3*v] [u, (a*u - u^2)/v] [1/2*a, -1/2*(a*u - u^2 - v^2)/v]
var('x y')

(x, y)
#Line through two points, cm and oc
z=? #convert the center of mass into complex number
S=[oc-cm,oc-cm]#Find a direction vector of the line
n=[?,?]# Find a normal to the line
euler=line_eq(?,?);euler #lhs of the line equation

-1/9*(a - 2*u)*(v - 3*y) + 1/9*(a + u - 3*x)*(v - 3*(a*u - u^2)/v)
test=euler.subs(x=?,y=?)# Check if the line passes through the intersection of bisectors

test.expand()

0
#Part 3: Plotting
# Use command 'point' to plot the three points
# Use command 'line' to plot Euler's line
# Use command polygon2d for plotting the triangle ABC. Choose any coordinates for the vertices provided the vertices do not lie on a line.
#Show all three plots in one figure. Add legend to the line if you want.

var('a')
var('b')
var('c')

a b c
pt_plot=point(a,size=30,color='red',figsize=[4,4],legend_label=a)
pt_plot=point(b,size=30,color='green',figsize=[4,4],legend_label=b)
pt_plot=point(c,size=30,color='blue',figsize=[4,4],legend_label=c)
triangle=polygon2d([[z1.real(),z1.imag()],[z2.real(),z2.imag()],[z2.real(),z2.imag()]],fill=False)
d=line([a,b,c],color='red',legend_label='Eulers line')
show(pt_plot+pt_plot1+pt_plot2+triangle+d)
pt1=5+4*I;
pt2=4+3*I;
pt3=3+2*I
plotting_euler(pt1,pt2,pt3)
plotting_euler(4+2*I,5+3*I,1+4*I)


Error in lines 4-4 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1191, in execute flags=compile_flags), namespace, locals) File "", line 1, in <module> NameError: name 'z1' is not defined
#Mini-project: Euler's line
reset

<function reset at 0x7fc9193df050>
#Part 1

#Center of mass of a triangle
#//Imput:?
#//Output:?
def center_of_mass(z1,z2,z3):# triangle ABC: C(z3),B(z2),A(z1);format:z=a+b*I
m23=? #Find the midpoint of AB
# Use the remark from Lecture notes to calculate the center of mass
cm=z1+(2/3)*(?)
return [cm.real(),cm.imag()]

#Example
#Triangle ABC; A(u,v),B(a,0),C(0,0)
var('u v a');assume(u,'real');assume(v,'real');assume(a,'real');

(u, v, a)
center_of_mass(u+v*I,a+0*I,0+0*I)

[1/3*a + 1/3*u, 1/3*v]
#Useful command: solving system of two linear equations
#solve?
#Example
sol=solve([2.3*x-3.*y+1.1==0.0,x+y-2.5==0.0],x,y,solution_dict=true);sol

[{y: 137/106, x: 64/53}]
[sol[x],sol[y]] #This is how you can access the solution values and make a list of these values

[64/53, 137/106]
#Useful function: line_eq(z,S) returns the lhs of the equation a*(x-x0)+b(y-y0)=0 of the line passing through a point z=x0+i*y0 and having normal [a,b]
def line_eq(z,n):
return n*(x-z.real())+n*(y-z.imag())

#Example
line_eq(3+2*I,[3,-2])

3*x + 2*y - 13
#Orthocenter
def orthocenter(z1,z2,z3):
#left hand sides of eqs of two heights of the triangle
s23=z3-z2 n1=[?,?]#encode coordinates of a normal of the height from point z1
expr1=line_eq(?,?)# lhs of eq of height from vertex z1
s13=z3-z1; n2=[?,?]#encode coordinated of a normal of the height from point z2
expr2=line_eq(?,?)# lhs of eq of height from vertex z2
sol=solve([expr1==0,expr2==0],x,y,solution_dict=True)#Orthocenter coordinates
return [sol[x], sol[y]]


pt1=5+3*I;pt2=4+0*I;pt3=0+0*I

O=orthocenter(pt1,pt2,pt3);O

[5, -5/3]
#Center of circumscribed circle
def bisector_cross(z1,z2,z3):
m23=(z3+z2)/2
s23=z3-z2; n1=? #Normal to bicector erected from the midpoint of the side connecting z3 and z2
expr1=line_eq(m23,n1)
m13=(z1+z3)/2
s13=z3-z1;n2=?#Normal to bicector erected from the midpoint of the side connecting z3 and z1
expr2=line_eq(m13,n2)
sol=solve([expr1==0,expr2==0],x,y,solution_dict=True)#Coordinates of the bisector intersection
return [sol[x], sol[y]]

#Part 2.
#(a) Show manually that the three special points of the triangle ABC with A=pt1, B=pt2, C=pt3,lie on a line

#C=bisector_cross(pt1,pt2,pt3);C

#M=center_of_mass(pt1,pt2,pt3);M

#H=orthocenter(pt1,pt2,pt3);H

#(b) Prove that the special points of the triangle ABC with A=u+I*v, B=a, C=0+0*I,lie on a line

var('u v a');assume(u,'real');assume(v,'real');assume(a,'real');

(u, v, a)
A=u+I*v; B=a+I*0; C=0+0*I

Find the center of mass,cm, the orthocenter,oc, and the bisector intercection,bc

cm=?
oc=?
bc=?

[1/3*a + 1/3*u, 1/3*v] [u, (a*u - u^2)/v] [1/2*a, -1/2*(a*u - u^2 - v^2)/v]
var('x y')

(x, y)
#Line through two points, cm and oc
z=? #convert the center of mass into complex number
S=[oc-cm,oc-cm]#Find a direction vector of the line
n=[?,?]# Find a normal to the line
euler=line_eq(?,?);euler #lhs of the line equation

-1/9*(a - 2*u)*(v - 3*y) + 1/9*(a + u - 3*x)*(v - 3*(a*u - u^2)/v)
test=euler.subs(x=?,y=?)# Check if the line passes through the intersection of bisectors

test.expand()

0
#Part 3: Plotting
# Use command 'point' to plot the three points
# Use command 'line' to plot Euler's line
# Use command polygon2d for plotting the triangle ABC. Choose any coordinates for the vertices provided the vertices do not lie on a line.
#Show all three plots in one figure. Add legend to the line if you want.
︠ff98d647-1c69-4b61-ba0b-547243d8d404︠