【问题标题】:find point of intersection between line and altitude找到线和高度之间的交点
【发布时间】:2014-12-29 20:14:27
【问题描述】:

我试图找到一条线与该线的高度之间的交点。因此,鉴于信息,创建一条线的两个点和一个绘制高度的点,我想找到最接近该点的线上的点,(所以线上的一个点与给定点。)

(希望没有说明是有道理的)

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

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

【问题讨论】:

  • 你会画画吗?更容易理解你需要什么。 :)
  • 是的,没有插图就没有意义
  • 我的错我没有可以做到这一点的绘画程序,但有人已经回答了这个问题。因此,对于将来遇到同样问题的人来说,我会按照我的意思做一些 askii 艺术...(之后,如果有人想制作一张真实的照片并将其发送给我,我很乐意替换它)

标签: java geometry point


【解决方案1】:
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();

【讨论】:

  • 天哪,非常感谢...是的,就是这样!
猜你喜欢
  • 2021-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-09
  • 1970-01-01
  • 1970-01-01
  • 2017-08-18
  • 1970-01-01
相关资源
最近更新 更多