Guest User

Untitled

a guest
Feb 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 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.         if (Double.isNaN(mA) == true) {
  16.            
  17.             double bC = midpointC.getY() - (midpointC.getX() * mC);
  18.             double bB = midpointB.getY() - (midpointB.getX() * mB);
  19.  
  20.             x = (bC - bB) / (mB - mC);
  21.             y = mC * x + bC;
  22.            
  23.         }
  24.         else if (Double.isNaN(mC) == true) {
  25.  
  26.             double bB = midpointB.getY() - (midpointB.getX() * mB);
  27.             double bA = midpointA.getY() - (midpointA.getX() * mA);
  28.  
  29.             x = (bB - bA) / (mA - mB);
  30.             y = mB * x + bA;
  31.            
  32.         }
  33.         else if (Double.isNaN(mB) == true) {
  34.  
  35.             double bA = midpointA.getY() - (midpointA.getX() * mA);
  36.             double bC = midpointC.getY() - (midpointC.getX() * mC);
  37.  
  38.             x = (bA - bC) / (mC - mA);
  39.             y = mA * x + bC;
  40.            
  41.         }
  42.  
  43.         Point circumcenter = new Point(x, y);
  44.         return circumcenter;
  45.     }
Add Comment
Please, Sign In to add comment