0

为了描述这个问题,我在下图中举了一个例子。

可以看出,有一条线 AB 及其指定的点 p1。对于这一行我有一个对应的行,即CD。我正在寻找点 p2 的坐标。点 p2 与直线 CD 的关系应与点 p1 与直线 AB 的关系相同(距离 d 相同,长度 m 相同)。我有点 A、B、p1、C、D 的坐标,我正在寻找 p2。一般来说,d 和 m 可以接受线 CD 和点 p2 的比例因子,我们已经知道这一点。

您可能知道,该问题在 CD 行的左侧有另一个假解,例如 p3,我们应该避免这种情况。

在我真正的问题中,我有 10 条线 AB 和大约 500 点,如 p1 分配给不同的线 AB。我有十个对应的线CD,我正在寻找500个对应点p2。

使用代数和几何可以解决问题,但我正在寻找一种快速有效的 C++ 实现方法。

非常感谢您的意见和建议。

在此处输入图像描述

4

1 回答 1

1

首先,为了简单起见,您需要将 AB 的任何运动表示为围绕单个点的旋转和平移,例如点 A。然后,对于需要与 AB 一起旋转的任何其他点,您应该通过减去点 A 将该点移动到线 AB 的空间中,然后通过在平移后将新点 A 添加回它来将其转换回世界空间和旋转。

我手头没有公式,但我会尝试挖掘一个例子。

编辑
未经测试的代码:

void transform_points(const point2f &center, vector<point2f> &points, const point2f &offset, float angle)
{
    // transform points into a space where 'center' is the origin
    mat3f to_origin = mat3f(1, 0, -center.x,
                            0, 1, -center.y,
                            0, 0, 1);

    // rotate the points around the origin
    mat3f rot = mat3f(cos(angle), -sin(angle), 0,
                      sin(angle),  cos(angle), 0,
                      0, 0, 1);

    // move the points back into world space
    mat3f to_world = mat3f(1, 0, center.x,
                           0, 1, center.y,
                           0, 0, 1);

    // offset the points by 'offset'
    mat3f off = mat3f(1, 0, offset.x,
                      0, 1, offset.y,
                      0, 0, 1);

    // concatenate all transformations for efficiency
    mat3f xform = off * to_world * rot * to_origin;

    // this loop could be parallelized using SIMD or multiple cores
    for(auto &p : points)
        p = xform * p;
}
于 2014-06-11T14:36:04.950 回答