using
System;
class
GFG {
public
static
void
lineFromPoints(
double
[] P,
double
[] Q,
ref
double
a,
ref
double
b,
ref
double
c)
{
a = Q[1] - P[1];
b = P[0] - Q[0];
c = a * (P[0]) + b * (P[1]);
}
public
static
void
perpendicularBisector(
double
[] P,
double
[] Q,
ref
double
a,
ref
double
b,
ref
double
c)
{
double
[] mid_point = {(P[0] + Q[0]) / 2,
(P[1] + Q[1]) / 2};
c = -b * (mid_point[0])
+ a * (mid_point[1]);
double
temp = a;
a = -b;
b = temp;
}
static
double
[] lineLineIntersection(
double
a1,
double
b1,
double
c1,
double
a2,
double
b2,
double
c2)
{
double
determinant = a1 * b2 - a2 * b1;
double
x = (b2 * c1 - b1 * c2)
/ determinant;
double
y = (a1 * c2 - a2 * c1)
/ determinant;
double
[]temp = {x, y};
return
temp;
}
static
double
[] findCircumCenter(
double
[,]A)
{
double
[] P =
new
double
[2];
for
(
int
i= 0; i < 2; i++){
P[i] = A[0, i];
}
double
[] Q =
new
double
[2];
for
(
int
i = 0; i < 2; i++){
Q[i] = A[1, i];
}
double
[] R =
new
double
[2];
for
(
int
i = 0; i < 2; i++){
R[i] = A[2, i];
}
double
a = 0.0;
double
b = 0.0;
double
c = 0.0;
lineFromPoints(P, Q,
ref
a,
ref
b,
ref
c);
double
e = 0.0;
double
f = 0.0;
double
g = 0.0;
lineFromPoints(Q, R,
ref
e,
ref
f,
ref
g);
perpendicularBisector(P, Q,
ref
a,
ref
b,
ref
c);
perpendicularBisector(Q, R,
ref
e,
ref
f,
ref
g);
double
[] circumcenter = lineLineIntersection(a, b, c, e, f, g);
return
circumcenter;
}
static
double
[] findCentroid(
double
[,]A)
{
double
[] centroid
= { (A[0, 0] + A[1, 0]
+ A[2, 0])
/ 3,
(A[0, 1] + A[1, 1]
+ A[2, 1])
/ 3 };
return
centroid;
}
static
public
void
findOrthocenter(
double
[,]A)
{
double
[]circumcenter = findCircumCenter(A);
double
[]centroid = findCentroid(A);
double
[]h = { (3 * centroid[0]
- 2 * circumcenter[0]),
(3 * centroid[1]
- 2 * circumcenter[1]) };
Console.WriteLine(
"("
+ Math.Round(h[0], 3) +
", "
+ Math.Round(h[1], 3) +
")"
);
}
static
void
Main()
{
double
[,]A = { { -3, 1 }, { 2, 2 }, { -3, -5 } };
findOrthocenter(A);
}
}