C#中如何检测直线是否相交?
我想在 C# 中添加项目的附加功能,我已经可以在程序中绘制线条,但我想检测绘制的一条线的相交线并显示它们相交的点。是否可以?谢谢
我的程序还包括垂直距离的计算,这里是示例代码:
public static Double PerpendicularDistance(Point Point1, Point Point2, Point Point)
{
Double area = Math.Abs(.5 * (Point1.X * Point2.Y + Point2.X * Point.Y + Point.X * Point1.Y - Point2.X * Point1.Y - Point.X * Point2.Y - Point1.X * Point.Y));
Double bottom = Math.Sqrt(Math.Pow(Point1.X - Point2.X, 2) + Math.Pow(Point1.Y - Point2.Y, 2));
Double height = area / bottom * 2;
return height;
}
}
这里的 POINT 是我的 X 和 Y 坐标的类。
I want to add additional feature of my project in C#, I can already draw lines in my program but I want to detect INTERSECTING LINES of a one line drawn and display the point they've intersect. Is it possible? Thank you
My program also includes computing for Perpendicular Distance, here is the sample code:
public static Double PerpendicularDistance(Point Point1, Point Point2, Point Point)
{
Double area = Math.Abs(.5 * (Point1.X * Point2.Y + Point2.X * Point.Y + Point.X * Point1.Y - Point2.X * Point1.Y - Point.X * Point2.Y - Point1.X * Point.Y));
Double bottom = Math.Sqrt(Math.Pow(Point1.X - Point2.X, 2) + Math.Pow(Point1.Y - Point2.Y, 2));
Double height = area / bottom * 2;
return height;
}
}
The POINT here is a class for my X and Y coordinates.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您试图找到两条线的交点,那么解决方案相当简单。
如果两条线的形式为 Ax + By = C:
我担心的是上面的评论,说只有一条画线。我不确定你的意思。这是否意味着应用程序提供一条线,而用户提供另一条线,还是我们正在处理线与自身相交的曲线?
If you are trying to find the intersection of two line, then the solution is fairly trivial.
If the two line are in the form Ax + By = C:
My concern is comment above that says there is only one drawn line. I'm not sure what you mean. Does it mean that the app provides one line and the user the other, or are we dealing in curved lines where the line intersects itself?