Skip to content

Commit

Permalink
almost right
Browse files Browse the repository at this point in the history
  • Loading branch information
johnprif committed Feb 15, 2023
1 parent 289cd10 commit 7f10be7
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions src/Model/DataBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public void prepareForAlgorithm(int mode)
{
this.mode = mode;
loadMaps();
if(mode == 1 || mode == 2)
{
circle = getCircleShape();
}
}

// ----------O(nlog(n))---------------
Expand Down Expand Up @@ -450,13 +454,12 @@ public Point2D getUp(Point2D p)
double slope = (nextP.getY()-p.getY())/(nextP.getX()-p.getX());
double versticalSlope = -1/slope;
Point2D mid = new Point2D(mx, my);
Point2D myCentre = new Point2D(getCircleShape().getCenterX(), getCircleShape().getCenterY());
return getIntersectionOfLines(mid, versticalSlope, slope);
// return getIntersectionOfLines(mid, slope, myCentre, versticalSlope);

Point2D myCentre = new Point2D(circle.getCenterX(), circle.getCenterY());
return getIntersectionOfLines(mid, versticalSlope, slope);
}

public Point2D getIntersectionOfLines(Point2D point, double slope1, double slope2) {
public Point2D getIntersectionOfLines(Point2D point, double slope1, double slope2)
{
// Calculate y-intercept of each line
double yIntercept1 = point.getY() - slope1 * point.getX();
double yIntercept2 = point.getY() - slope2 * point.getX();
Expand All @@ -476,27 +479,6 @@ public Point2D getIntersectionOfLines(Point2D point, double slope1, double slope
}
}

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)----------------
public void addAllUpToK()
{
Expand Down

0 comments on commit 7f10be7

Please sign in to comment.