相关疑难解决方法(0)

如何选择一条线

所以我试图弄清楚如何实现在绘图区域中选择线条或边缘的方法,但我的数学有点缺乏.这是我到目前为止所得到的:

  • 一组线,每一行有两个端点(一个开始,一个开始结束)
  • 线条在画布上正确绘制
  • 单击画布时会收到鼠标单击事件,因此我可以获取鼠标指针的x和y坐标

我知道我可以遍历行列表,但我不知道如何构造一个算法来通过给定的坐标(即鼠标点击)选择一条线.有人有任何想法或指出我正确的方向?

// import java.awt.Point

public Line selectLine(Point mousePoint) {
    for (Line l : getLines()) {
        Point start = l.getStart();
        Point end = l.getEnd();
        if (canSelect(start, end, mousePoint)) {
            return l; // found line!
        }
    }
    return null; // could not find line at mousePoint
}

public boolean canSelect(Point start, Point end, Point selectAt) {
    // How do I do this?
    return false;
}
Run Code Online (Sandbox Code Playgroud)

java algorithm graphics 2d

2
推荐指数
2
解决办法
9028
查看次数

如何找到最接近一个点的矩形

如果我System.Drawing.Rectangle在画布和一个上有两个对象,计算哪个( 的任何部分,而不仅仅是它的)最接近那个Point最佳方法是什么?RectangleRectangleLocation PointPoint

一个单元测试的例子:

Rectangle one = new Rectangle (0, 0, 10, 10);

Rectangle two = new Rectangle (20, 20, 10, 10);

Point point = new Point(14, 14);

Rectangle actual = ClosestToPoint(point, one, two);

// should be closer to one since one's bottom right is at (10, 10)
Assert.That(actual, Is.SameAs(one));

// method to write
public Rectangle ClosestToPoint(Point p, params Rectangle[] rectangles) { } 
Run Code Online (Sandbox Code Playgroud)

c# geometry system.drawing

2
推荐指数
1
解决办法
5085
查看次数

计算点到直线的距离

我正在用 C# 编写一个类似绘画的程序。我希望能够在单击靠近一条线时擦除该线(例如,距离 < 10 像素)。我尝试了不同的计算,但最终遇到的问题是,只有当我单击线条的起点或终点附近时,线条才会被删除。介于两者之间的任何事情似乎都不起作用。

令 p 为用户在表单中单击的点,startp 和 endp 为线条的终点。

double a = (endp.Y - startp.Y) / (endp.X - startp.X); // gradient
double b = endp.Y - a * endp.X; // y intercept

// condition such that it only works when i click close to the line segment,
// not the entire infinite line for which the calculation y=ax+b works

double yvalue = p.X * a + b;    // value the line segment has at the x-value which …
Run Code Online (Sandbox Code Playgroud)

c# geometry

2
推荐指数
1
解决办法
4408
查看次数

如何判断质心点是否接触直线?

我正在研究一种基于越线检测的入侵检测算法。我使用方程 y = mx+c 开发了一种基本算法,但当人靠近线时,它显示出一些错误的检测。我需要一些建议来使其成为完美的线接触算法。

在此输入图像描述

在此输入图像描述

opencv computer-vision intrusion-detection python-3.x deep-learning

2
推荐指数
1
解决办法
707
查看次数

在折线/路径中查找最近的点

我需要从给定CLLocationCoordinate2D的数组中找到最近的点GMSPolyline.GMSPath如果那更好的话,我可以将其转换为.是否有任何现成的方法(或任何存储库)进行此类计算?我在实施方面遇到了一些问题.我想知道如何创建一个算法:

1. for all polylines
1.1. find smallest distance between polyline and touch point, save CLLocationCoordinate2D
2. for all distances from point 1.1.
2.1. find the shortest one, it's CLLocationCoordinate2D is our point
Run Code Online (Sandbox Code Playgroud)

现在的问题是如何实现1.1点?

基于SOF最短距离问题,我写了这样的代码:

- (void)findNearestLineSegmentToCoordinate:(CLLocationCoordinate2D)coordinate {
    GMSPolyline *bestPolyline;
    double bestDistance = DBL_MAX;
    CGPoint originPoint = CGPointMake(coordinate.longitude, coordinate.latitude);
    for (GMSPolyline *polyline in self.polylines) {
        polyline.strokeColor = [UIColor redColor]; // TMP

        if (polyline.path.count < 2) { // we need at least 2 …
Run Code Online (Sandbox Code Playgroud)

google-maps objective-c polyline ios

1
推荐指数
1
解决办法
4200
查看次数