相关疑难解决方法(0)

给定两个顶点围绕中心点旋转线

我一直试图将一堆线旋转90度(它们一起形成折线).每行包含两个顶点,例如(x1,y1)和(x2,y2).我目前要做的是围绕线的中心点旋转,给定中心点| x1 - x2 | 和| y1 - y2 |.出于某种原因(我不是在数学上非常精明)我无法正确旋转线条.

有人可以验证这里的数学是否正确?我认为它可能是正确的,但是,当我将线的顶点设置为新的旋转顶点时,下一行可能无法从上一行抓取新的(x2,y2)顶点,导致线条不正确地旋转.

这是我写的:

def rotate_lines(self, deg=-90):
    # Convert from degrees to radians
    theta = math.radians(deg)

    for pl in self.polylines:
        self.curr_pl = pl
        for line in pl.lines:
            # Get the vertices of the line
            # (px, py) = first vertex
            # (ox, oy) = second vertex
            px, ox = line.get_xdata()
            py, oy = line.get_ydata()

            # Get the center of the line
            cx = math.fabs(px-ox)
            cy = math.fabs(py-oy)

            # Rotate line around center …
Run Code Online (Sandbox Code Playgroud)

python trigonometry rotation

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

标签 统计

python ×1

rotation ×1

trigonometry ×1