find first the equation of the median AM it is the line that connects the vertex A with the mid point of BC .
This line has equation as per your coordinates of the vertices A(p1,q1), B(p2,q2),C(p3,q3).
the equation of the median :
AM IS: (q2+q3-2q1)x-(p2+p3-2p1)y+(p2q1-q2p1)+(p3q1-q3p1)=0
the median BE is : (q1+q3-2q2)x-(p1+p3-2p2)y+(p3q2-q3p2)+(p1q2-q1p2)=0
the median CZ is : (q1+q2-2q3)x-(p1+p2-2p3)y+(p1q3-q1p3)+(p2q3-q2p3)=0
if these 3 lines meet in one point then they form a pencil of lines.
the condition that 3 lines form a pencil of lines is that the determinant of their coefficients = 0
ex given if the lines a1x+b1y+C1=0 , a2x+b2y+c2=0 and a3x+b3y+c3=0 form a pencil of lines then the determinant of the coefficients a1,b2,c1,...etc =0
solve the system of the 3 equations I have given you to find their common point. WHOSE COORDINATES MUST BE (p1,+p2+p3)/3 AND (q1+q2+q3)/3
this is the barycenter of the triangle ABC...
I hope you understand all the above...