Skip to content

Commit

Permalink
almost fix voronoi edges
Browse files Browse the repository at this point in the history
  • Loading branch information
johnprif committed Feb 15, 2023
1 parent 2f664fc commit 289cd10
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/Model/DataBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ private double getAngle(Point2D p, Point2D q, Point2D r)
return Math.acos((a + b - c) / Math.sqrt(4 * a * b));
}

public Point2D getUp(Point2D p)
public Point2D getUp2(Point2D p)
{
Point2D nextP = neighbours.get(p).get(1); //O(1)
double mx = (p.getX() + nextP.getX()) / 2.0;
Expand All @@ -442,7 +442,7 @@ public Point2D getUp(Point2D p)
return new Point2D(ux, uy);
}

public Point2D getUp2(Point2D p)
public Point2D getUp(Point2D p)
{
Point2D nextP = neighbours.get(p).get(1); //O(1)
double mx = (p.getX() + nextP.getX()) / 2.0;
Expand All @@ -451,8 +451,9 @@ public Point2D getUp2(Point2D p)
double versticalSlope = -1/slope;
Point2D mid = new Point2D(mx, my);
Point2D myCentre = new Point2D(getCircleShape().getCenterX(), getCircleShape().getCenterY());
// return getClosestPointOnLine(mid, versticalSlope, myCentre);
return getIntersectionOfLines(mid, slope, versticalSlope);
return getIntersectionOfLines(mid, versticalSlope, slope);
// return getIntersectionOfLines(mid, slope, myCentre, versticalSlope);

}

public Point2D getIntersectionOfLines(Point2D point, double slope1, double slope2) {
Expand All @@ -474,6 +475,26 @@ public Point2D getIntersectionOfLines(Point2D point, double slope1, double slope
return null;
}
}

public Point2D getIntersectionOfLines2(Point2D point1, double slope1, Point2D point2, double slope2) {
// Calculate y-intercept of each line
double yIntercept1 = point1.getY() - slope1 * point1.getX();
double yIntercept2 = point2.getY() - slope2 * point2.getX();

// Check if slopes are not equal
if (slope1 != slope2) {
// Calculate x-coordinate of intersection point
double x = (yIntercept2 - yIntercept1) / (slope1 - slope2);

// Calculate y-coordinate of intersection point
double y = slope1 * x + yIntercept1;

return new Point2D(x, y);
} else {
// Lines are parallel, so they don't intersect
return null;
}
}


//-----------O(n)----------------
Expand Down

0 comments on commit 289cd10

Please sign in to comment.