CartesianPoint::"usage" = "CartesianPoint[lista] translates projective coordinates into cartesian coordinates.";

CartesianPoint[{x_,y_,z_}]:={x/z,y/z}

Simplificar::"usage" = "Simplificar[expr removes common factors of the elements of a list.";

Simplificar[lista_]:=Simplify[lista/Apply[PolynomialGCD,lista]]

Punto::"usage" = "Punto[r,s] returns the point of intersection of two lines r and s.";

Punto[r_,s_]:=Simplificar[Cross[r,s]];

Recta::"usage" = "Recta[ptP,ptQ] returns the line through the points r and s.";

Recta[ptP_,ptQ_]:=Punto[ptP,ptQ];

DividirSegmento::"usage" = "DividirSegmento[ptP,ptQ,m,n] returns the point that divides the segment PQ in the ratio m:n";

DividirSegmento[{x1_,y1_,z1_},{x2_,y2_,z2_},m_,n_]:=Simplificar[{m x2 z1+n x1 z2,m y2 z1+n y1 z2,(m+n) z1 z2}];

Medio::"usage" = "Medio[ptA,ptB] returns the midpoint of the segment AB.";

Medio[ptA_,ptB_]:=DividirSegmento[ptA,ptB,1,1];

Perpendicular::"usage" = "Perpendicular[ptA,ptB,ptC] returns the line through A perpendiucular to BC.";

Perpendicular[{x1_,y1_,z1_},{x2_,y2_,z2_},{x3_,y3_,z3_}]:=Simplificar[{z1 (x3 z2-x2 z3),z1 (y3 z2-y2 z3),-x1 x3 z2-y1 y3 z2+x1 x2 z3+y1 y2 z3}]

Paralela::"usage" = "Paralela[ptA,ptB,ptC] returns the line through A parallel to BC.";

Paralela[{x1_,y1_,z1_},{x2_,y2_,z2_},{x3_,y3_,z3_}]:=
Simplificar[{z1 (y3 z2-y2 z3),-z1 (x3 z2-x2 z3),x3 y1 z2-x1 y3 z2-x2 y1 z3+x1 y2 z3}]

Mediatriz::"usage" = "Mediatriz[ptA,ptB] returns the perpendicular bisector of segment BC.";

Mediatriz[ptA_, ptB_] := Perpendicular[Medio[ptA, ptB], ptA, ptB]

Circuncentro::"usage" = "Circuncentro[{ptA,ptB,ptC}] returns the circumcenter of the triangle BC.";

Circuncentro[{ptA_,ptB_,ptC_}]:=Punto[Mediatriz[ptA,ptB],Mediatriz[ptA,ptC]]

Ortocentro::"usage" = "Ortocentro[{ptA,ptB,ptC}] returns the orthocenter of the triangle BC.";

Ortocentro[{ptA_,ptB_,ptC_}]:=Punto[Perpendicular[ptB,ptA,ptC],Perpendicular[ptC,ptA,ptB]]

Baricentro::"usage" = "Baricentro[{ptA,ptB,ptC}] returns the centroid of the triangle BC.";

Baricentro[{ptA_,ptB_,ptC_}]:=DividirSegmento[ptA,Medio[ptB,ptC],2,1];

CentroNuevePuntos::"usage" = "CentroNuevePuntos[{ptA,ptB,ptC}] returns the nine point center of the triangle BC.";

CentroNuevePuntos[trT_]:=DividirSegmento[Circuncentro[trT],Ortocentro[trT],1,1]

CircunferenciaTresPuntos::"usage" = "CircunferenciaTresPuntos[{ptA,ptB,ptC}] returns the equation of the circle through three points.";

CircunferenciaTresPuntos[{{x1_,y1_,z1_},{x2_,y2_,z2_},{x3_,y3_,z3_}}]:=-x2 (x3^2) y1 (z^2) z1 z2+x1 (x3^2) y2 (z^2) z1 z2-x2 y1 (y3^2) (z^2) z1 z2+x1 y2 (y3^2) (z^2) z1 z2+x2 (x3^2) y z (z1^2) z2-x (x3^2) y2 z (z1^2) z2+x2 y (y3^2) z (z1^2) z2-x y2 (y3^2) z (z1^2) z2-x1 (x3^2) y z z1 (z2^2)+x (x3^2) y1 z z1 (z2^2)-x1 y (y3^2) z z1 (z2^2)+x y1 (y3^2) z z1 (z2^2)+(x2^2) x3 y1 (z^2) z1 z3+x3 y1 (y2^2) (z^2) z1 z3-x1 (x2^2) y3 (z^2) z1 z3-x1 (y2^2) y3 (z^2) z1 z3-(x2^2) x3 y z (z1^2) z3-x3 y (y2^2) z (z1^2) z3+x (x2^2) y3 z (z1^2) z3+x (y2^2) y3 z (z1^2) z3-(x1^2) x3 y2 (z^2) z2 z3-x3 (y1^2) y2 (z^2) z2 z3+(x1^2) x2 y3 (z^2) z2 z3+x2 (y1^2) y3 (z^2) z2 z3+(x^2) x3 y2 (z1^2) z2 z3+x3 (y^2) y2 (z1^2) z2 z3-(x^2) x2 y3 (z1^2) z2 z3-x2 (y^2) y3 (z1^2) z2 z3+(x1^2) x3 y z (z2^2) z3+x3 y (y1^2) z (z2^2) z3-x (x1^2) y3 z (z2^2) z3-x (y1^2) y3 z (z2^2) z3-(x^2) x3 y1 z1 (z2^2) z3-x3 (y^2) y1 z1 (z2^2) z3+(x^2) x1 y3 z1 (z2^2) z3+x1 (y^2) y3 z1 (z2^2) z3+x1 (x2^2) y z z1 (z3^2)-x (x2^2) y1 z z1 (z3^2)+x1 y (y2^2) z z1 (z3^2)-x y1 (y2^2) z z1 (z3^2)-(x1^2) x2 y z z2 (z3^2)-x2 y (y1^2) z z2 (z3^2)+x (x1^2) y2 z z2 (z3^2)+x (y1^2) y2 z z2 (z3^2)+(x^2) x2 y1 z1 z2 (z3^2)+x2 (y^2) y1 z1 z2 (z3^2)-(x^2) x1 y2 z1 z2 (z3^2)-x1 (y^2) y2 z1 z2 (z3^2);

ConicaCincoPuntos::"usage" = "ConicaCincoPuntos[{ptA,ptB,ptC,ptE,ptF}] returns the equation of the conic through five points.";

ConicaCincoPuntos[{{x1_,y1_,z1_},{x2_,y2_,z2_},{x3_,y3_,z3_},{x4_,y4_,z4_},{x5_,y5_,z5_}}]:=Factor[Det[{{(x^2),(y^2),(z^2),y z,z x,x y},{(x1^2),(y1^2),(z1^2),y1 z1,z1 x1,x1 y1},{(x2^2),(y2^2),(z2^2),y2 z2,z2 x2,x2 y2},{(x3^2),(y3^2),(z3^2),y3 z3,z3 x3,x3 y3},{(x4^2),(y4^2),(z4^2),y4 z4,z4 x4,x4 y4},{(x5^2),(y5^2),(z5^2),y5 z5,z5 x5,x5 y5}}]]

CentroConica::"usage" = "CentroConica[conic] returns the center of a conic.";

CentroConica[conic_] :=Simplificar[ {x,y,z}/.Solve[{D[conic,x]==0,D[conic,y]==0},{x,y}][[1]]]

EjeDeHomografia::"usage" = "EjeDeHomografia[{A1,B1,C1},{A2,B2,C2}] returns the axis of the homography between the lines A1B1C1 and A2B2C2 that maps A1, B1, C1 on A2, B2, C2 respectively.";

EjeDeHomografia[{ptA1_,ptB1_,ptC1_},{ptA2_,ptB2_,ptC2_}]:=Recta[
Punto[Recta[ptA1,ptB2],Recta[ptA2,ptB1]],
Punto[Recta[ptA1,ptC2],Recta[ptA2,ptC1]]]

ProjectiveTransformation::"usage" = "ProjectiveTransformation[{A1,B1,C1,D1},{A2,B2,C2,D2},M] returns image of M by the plane projective transformation that maps the the quadrangle ABCD on the quadrangle A2B2C2D.";

ProjectiveTransformation[{ptA1_,ptB1_,ptC1_,ptD1_},{ptA2_,ptB2_,ptC2_,ptD2_},ptM_]:=Module[{ptS1,ptS2,ptXC,ptXD,ptYC,ptYD,eje},
ptS1=Punto[Recta[ptA1,ptB1],Recta[ptC1,ptD1]];
ptS2=Punto[Recta[ptA2,ptB2],Recta[ptC2,ptD2]];
eje=EjeDeHomografia[{ptA1,ptB1,ptS1},{ptA2,ptB2,ptS2}];
ptXC=Punto[Recta[ptC1,ptM],Recta[ptA1,ptB1]];
ptXD=Punto[Recta[ptD1,ptM],Recta[ptA1,ptB1]];
ptYC=Punto[Recta[ptA2,ptB2],Recta[ptA1,Punto[Recta[ptXC,ptA2],eje]]];
ptYD=Punto[Recta[ptA2,ptB2],Recta[ptA1,Punto[Recta[ptXD,ptA2],eje]]];
Punto[Recta[ptC2,ptYC],Recta[ptD2,ptYD]]
]

ptA={0,1,1};
ptB={1,2,1};
ptC={5,9,1};
ptD={3,1,1};
ptE={2,5,1};

line between two points

Recta[ptA,ptB]

intersection point two lines

Punto[Recta[ptA,ptB],Recta[ptA,ptC]]

ratiopoint between two other points (DividirRazon)

DividirSegmento[ptA,ptB,3,1]

line through a point perpendicular at another line

Perpendicular[ptA,ptB,ptC]

Paralela[ptA,ptB,ptC]

perpendicular bisector between two points

Mediatriz[ptB,ptC]

circumcenter, orthocenter, centroid, nine - point center in a triangle

Circuncentro[{ptA,ptB,ptC}]

Ortocentro[{ptA,ptB,ptC}]

Baricentro[{ptA,ptB,ptC}]

CentroNuevePuntos[{ptA,ptB,ptC}]

circle through three points

circun=CircunferenciaTresPuntos[{ptA,ptB,ptC}]

conic through five points

conic=ConicaCincoPuntos[{ptA,ptB,ptC,ptD,ptE}]

center of a conic

CentroConica[conic]

CentroConica[circun]

Graphics

{cA,cB,cC,cD,cE}=Map[CartesianPoint,{ptA,ptB,ptC,ptD,ptE}];
cconic=conic/.z->1;
mAB=Mediatriz[ptA,ptB].{x,y,1};

Show[{
ContourPlot[cconic==0,{x,-15,15},{y,-15,15}],
ContourPlot[mAB==0,{x,-15,15},{y,-15,15}],
Graphics[{
Style[Text["A",cA,{0,1.5}],16,Italic,Red],
Style[Text["D",cD,{0,1.5}],16,Italic,Red],
Style[Text["B",cB,{0,-1.5}],16,Italic,Red],
PointSize[0.02],
Line[{cA,cD}],
Map[Point,{cA,cB,cC,cD,cE}]
}]
},Background->RGBColor[0.8,0.9,0.8]]

ptA1={1,0,1};
ptB1={1,1,1};
ptC1={0,1,1};
ptD1={0,0,1};

ptA2={3,4,1};
ptB2={4,5,1};
ptC2={5,1,1};
ptD2={2,0,1};

circun=CircunferenciaTresPuntos[{Medio[ptA1,ptB1],Medio[ptB1,ptC1],Medio[ptC1,ptD1]}]

conic=Last[Factor[
circun /.Thread[{x,y,z}-> ProjectiveTransformation[{ptA2,ptB2,ptC2,ptD2},{ptA1,ptB1,ptC1,ptD1},{x,y,z}]]]]

{cA1,cB1,cC1,cD1,cA2,cB2,cC2,cD2}=Map[CartesianPoint,{ptA1,ptB1,ptC1,ptD1,ptA2,ptB2,ptC2,ptD2}];
instr={
Line[{cA1,cB1,cC1,cD1,cA1}],
Line[{cA2,cB2,cC2,cD2,cA2}]
};

Show[{
Graphics[instr,AspectRatio->Automatic],
ContourPlot[(circun/.z->1)==0,{x,-2,2},{y,-2,2},ContourStyle->Blue],
ContourPlot[(conic /.z->1)==0,{x,-12,12},{y,-12,12},PlotPoints->100,ContourStyle->{Thick,Red}]}]