获取线段上的等分点
获取线段上的等分点可以用:定比分点公式
有向线段的起点和终点的坐标分别为x1和x2,分点M分此有向线段的比为λ,那么,分点M的坐标
x = (l - λ) * xl + λ * x2y = (l - λ) * yl + λ * y2
代码:
typedef struct {
int x, y;
} Point;
//接受一个线段的起点和终点坐标,要分多少个等分多少个点,vecPoint保存返回的点的结果
void BisectorSegmentPoint(Point pointX, Point pointY, float iCount, std::vector<Point> &vecPoint)
{
for (float i = 1; i <= iCount; i++)
{
float fSegment = i / iCount;
Point pointData = { 0, 0 };
pointData.x = (1-fSegment) * pointX.x + fSegment * pointY.x;
pointData.y = (1-fSegment) * pointX.y + fSegment * pointY.y;
vecPoint.push_back(pointData);
}
}
int main()
{
Point p1 = { 582409, 1153233 };
Point p2 = { 583616, 1153233 };
std::vector<Point> vecPoint;
BisectorSegmentPoint(p1, p2, 20, vecPoint);
return 0;
}