Equidistant points in a line segment

后端 未结 3 914
伪装坚强ぢ
伪装坚强ぢ 2021-01-25 06:13

Let assume you have two points (a , b) in a two dimensional plane. Given the two points, what is the best way to find the maximum points on the line segment that are equidistan

3条回答
  •  攒了一身酷
    2021-01-25 06:55

    Find the number of points that will fit on the line. Calculate the steps for X and Y coordinates and generate the points. Like so:

    lineLength = sqrt(pow(end.X - start.X,2) + pow(end.Y - start.Y, 2))
    numberOfPoints = floor(lineLength/minDistantApart)
    stepX = (end.X - start.X)/numberOfPoints
    stepY = (end.Y - start.Y)/numberOfPoints
    for (i = 1; i < numberOfPoints; i++) {
        yield Point(start.X + stepX*i, start.Y + stepY*i)
    }
    

提交回复
热议问题