In[]:=
VivianiTheorem::usage="Viviani's theorem says that in an equilateral triangle the distances of an inner point on each side add up to a length equal to that of its height. References: Personal, based in Viviani's theorem; Wolfram MathWorld: Triangle interior";
In[]:=
​​VivianiTheorem[{x11_,y11_},{x2_,y2_},{x3_,y3_},{vx_,vy_}]:=​​Module{},DEP=Det[{{x11,y11,1},{x2,y2,1},{x3,y3,1}}];​​P1={x11,y11};P2={x2,y2};P3={x3,y3};​​l1=N[Norm[P1-P2]];l2=N[Norm[P1-P3]];l3=N[Norm[P2-P3]];​​M1=
P1+P2
2
;v0={x11,y11};v1={x3-x11,y3-y11};v2={x2-x11,y2-y11};​​v={vx,vy};v0x=x11;v0y=y11;v2x=x2-x11;v2y=y2-y11;v1x=x3-x11;v1y=y3-y11;​​a1=
v0yv2x-v0xv2y+v2yvx-v2xvy
-v1yv2x+v1xv2y
;​​b1=
v0yv1x-v0xv1y+v1yvx-v1xvy
v1yv2x-v1xv2y
;​​Ifl1=!=l2||l1=!=l3!!l2=!=l3||DEP==0||a1<=0||b1<=0||a1+b1>=1,Print[PasteButton["It does not meet the conditions of Viviani's Theorem"]],​​d1=
Abs[(y2-y11)vx-(x2-x11)vy+y11(x2-x11)-x11(y2-y11)]
2
(y2-y11)
+
2
(x2-x11)
;​​d2=
Abs[(y3-y11)vx-(x3-x11)vy+y11(x3-x11)-x11(y3-y11)]
2
(y3-y11)
+
2
(x3-x11)
;​​d3=
Abs[(y3-y2)vx-(x3-x2)vy+y2(x3-x2)-x2(y3-y2)]
2
(y3-y2)
+
2
(x3-x2)
;​​h=N[d1+d2+d3];​​h1=N[Norm[M1-P3]];​​p=Grid[{{Height,DistancesSum},{h1,h}},FrameAll,ItemSize->15,ItemStyle->15];​​Print[p];​​Print[" "];​​s1=Solve[{(y-y11)(x2-x11)==(y2-y11)(x-x11),(y-vy)(y2-y11)==-(x2-x11)(x-vx)},{x,y}];​​xp11=x/.s1;xp1=xp11.{1};yp11=y/.s1;yp1=yp11.{1};​​s2=Solve[{(y-y11)(x3-x11)==(y3-y11)(x-x11),(y-vy)(y3-y11)==-(x3-x11)(x-vx)},{x,y}];​​xp22=x/.s2;xp2=xp22.{1};yp22=y/.s2;yp2=yp22.{1};​​s3=Solve[{(y-y2)(x3-x2)==(y3-y2)(x-x2),(y-vy)(y3-y2)==-(x3-x2)(x-vx)},{x,y}];​​xp33=x/.s3;xp3=xp33.{1};yp33=y/.s3;yp3=yp33.{1};​​g1=Line[{{x11,y11},{x2,y2},{x3,y3},{x11,y11}}];​​g2=Point[{vx,vy}];​​label[sym_,Point[pos_]]:={PointSize[Scaled[0.016]],Hue[0.58,1,1],Point[pos],Text[Style[sym,White,FontSizeScaled[0.015]],pos]};​​Show[{Graphics[{Blue,g1}],Graphics[{MapThread[label,{{
v
},{g2}}]}],Graphics[{DarkGreen,Thick,Line[{{vx,vy},{xp1,yp1}}]}],Graphics[{DarkGreen,Thick,Line[{{vx,vy},{xp2,yp2}}]}],Graphics[{DarkGreen,Thick,Line[{{vx,vy},{xp3,yp3}}]}],Graphics[{DarkGreen,PointSize[0.01],Point[{xp1,yp1}]}],Graphics[{DarkGreen,PointSize[0.01],Point[{xp2,yp2}]}],Graphics[{DarkGreen,PointSize[0.01],Point[{xp3,yp3}]}]},AxesTrue,AxesOrigin{0,0},AspectRatioAutomatic,ImageSize700,PlotLabelStyle[Framed["Viviani's Theorem:"],16,Blue,BackgroundYellow]]​​​​
Example:
In[]:=
VivianiTheorem[{3,3},{-3,-3},-3
3
,3
3
,{-2,1}]
Height
DistancesSum
7.34847
7.34847
Out[]=