Skip to content
The Chat Archive
gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)

QRectF ImageRect绕左上角旋转后,如何换算成绕中心点旋转的ImageRect?

  1. User

    QRectF ImageRect绕左上角旋转后,如何换算成绕中心点旋转的ImageRect?

  2. Assistant

    假设初始的 ImageRect 的左上角的坐标为 (x1, y1),宽度为 w,高度为 h。首先需要将左上角旋转后的坐标 (x1', y1') 换算成元素的中心点 (cx, cy) 坐标。可以通过以下公式得到:

    cx = x1' + w / 2
    cy = y1' + h / 2
    

    然后,以 (cx, cy) 为旋转中心,将旋转后的 ImageRect 换算成绕中心点旋转的 ImageRect。假设旋转角度为 angle,则新的 ImageRect 的左上角坐标为 (x2, y2),宽度和高度保持不变。可以使用以下公式计算:

    x2 = cx - w / 2 * cos(angle) + h / 2 * sin(angle)
    y2 = cy - h / 2 * cos(angle) - w / 2 * sin(angle)
    

    最后,新的 ImageRect 的左上角为 (x2, y2),宽度和高度与初始的 ImageRect 保持不变。