我试图找到一条线到该线的高度之间的交点。因此,鉴于信息,两个点创建了一条线,一个点从中绘制了高度,因此,我想在最接近该点的线上找到该点(因此,该点与直线形成一条垂直线)给定点。)

(希望没有病假的希望)

给定一条线和一个点,我将如何找到这个新点?

public static Point2D findPointOnTwoLines(Line2D line, Point2D point) {
    double slope = line.getSlope();
    double oppRec = line.getOppRecip(); // returns the opposite reciprocal of the slope
    double x = ((slope * line.getPoint1().getX()) - (line.getPoint1().getY()))
            / ((slope) - (oppRec));
    double y = (slope * ((oppRec * point.getX()) - point.getY())) - (oppRec * ((slope * point.getX()) - point.getY()))
            / ((slope) - (oppRec));

    return new Point2D(x, y);
}


这是我尝试使用确定子求解方程式的尝试,但通过时却未能给出正确的坐标:

Line2D line = new Line2D(2, 3, 1, 1); // line from (2, 3) to (1, 1)
Point2D point = new Point2D(0, 2);


如果您知道如何使用此方法(或其他任何方法)找到正确的点,将不胜感激!

我想说的是ASKII的艺术,如果您可以对此做一个真实的图像并将其发送给我,那么我很乐意使用它。

1
 \       3
  \     /
   \   /      the number points are thrown in as arguments, and the "X" point is returned
    \ /
     X    <---- this is a 90 degree angle
      \
       \        the "X" is suppose to represent the point on the line closest to the point "3"
        \
         2

最佳答案

double x = (point.getY() - oppRec * point.getX() - line.getPoint1().getY() + slope * line.getPoint1().getX()) / (slope - oppRec);
double y = oppRec * x + point.getY() - oppRec * point.getX();

10-08 18:07