Guest User

Untitled

a guest
Feb 18th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1.     public Point circumcenter() {
  2.        
  3.         // declare midpoints
  4.         Point midpointC = new Point(((a.getX() + b.getX()) / 2.0), (a.getY() + b.getY()) / 2.0);
  5.         Point midpointB = new Point(((a.getX() + c.getX()) / 2.0), (a.getY() + c.getY()) / 2.0);
  6.         Point midpointA = new Point(((b.getX() + c.getX()) / 2.0), (b.getY() + c.getY()) / 2.0);
  7.        
  8.         // declare slopes
  9.         double mC = -(a.getX() - b.getX()) / (a.getY() - b.getY());
  10.         double mB = -(a.getX() - c.getX()) / (a.getY() - c.getY());
  11.         double mA = -(c.getX() - b.getX()) / (c.getY() - b.getY());
  12.  
  13.         double x, y;
  14.        
  15.        
  16.             double bC = midpointC.getY() - (midpointC.getX() * mC);
  17.             double bB = midpointB.getY() - (midpointB.getX() * mB);
  18.  
  19.             x = (bC - bB) / (mB - mC);
  20.             y = mC * x + bC;
  21.  
  22.         if (Double.isNaN(mC) == true) {
  23.  
  24.             double bB = midpointB.getY() - (midpointB.getX() * mB);
  25.             double bA = midpointA.getY() - (midpointA.getX() * mA);
  26.  
  27.             x = (bB - bA) / (mA - mB);
  28.             y = mB * x + bA;
  29.            
  30.         }
  31.         else if (Double.isNaN(mB) == true) {
  32.  
  33.             double bA = midpointA.getY() - (midpointA.getX() * mA);
  34.             double bC = midpointC.getY() - (midpointC.getX() * mC);
  35.  
  36.             x = (bA - bC) / (mC - mA);
  37.             y = mA * x + bC;
  38.            
  39.         }
  40.  
  41.         Point circumcenter = new Point(x, y);
  42.         return circumcenter;
  43.     }
Add Comment
Please, Sign In to add comment