Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Point circumcenter() {
- // declare midpoints
- Point midpointC = new Point(((a.getX() + b.getX()) / 2.0), (a.getY() + b.getY()) / 2.0);
- Point midpointB = new Point(((a.getX() + c.getX()) / 2.0), (a.getY() + c.getY()) / 2.0);
- Point midpointA = new Point(((b.getX() + c.getX()) / 2.0), (b.getY() + c.getY()) / 2.0);
- // declare slopes
- double mC = -(a.getX() - b.getX()) / (a.getY() - b.getY());
- double mB = -(a.getX() - c.getX()) / (a.getY() - c.getY());
- double mA = -(c.getX() - b.getX()) / (c.getY() - b.getY());
- double x, y;
- double bC = midpointC.getY() - (midpointC.getX() * mC);
- double bB = midpointB.getY() - (midpointB.getX() * mB);
- x = (bC - bB) / (mB - mC);
- y = mC * x + bC;
- if (Double.isNaN(mC) == true) {
- double bB = midpointB.getY() - (midpointB.getX() * mB);
- double bA = midpointA.getY() - (midpointA.getX() * mA);
- x = (bB - bA) / (mA - mB);
- y = mB * x + bA;
- }
- else if (Double.isNaN(mB) == true) {
- double bA = midpointA.getY() - (midpointA.getX() * mA);
- double bC = midpointC.getY() - (midpointC.getX() * mC);
- x = (bA - bC) / (mC - mA);
- y = mA * x + bC;
- }
- Point circumcenter = new Point(x, y);
- return circumcenter;
- }
Add Comment
Please, Sign In to add comment