Calculate a vector from the center of a square to edge based on radius

前端 未结 5 1902
Happy的楠姐
Happy的楠姐 2021-01-06 12:58

Given a square (described by x, y, width, height) and an angle (in radians) I need to calculate a vector that originates at the squares centre and terminates at the point th

5条回答
  •  爱一瞬间的悲伤
    2021-01-06 13:37

    Given the square's width and height you can then determine the center of the square (x+.5w, y+.5h).

    From there, you can use some trigonometry to determine the length of the vector line:

    tan(angle) = 0.5x / a

    where a = the distance between the center of the square and the edge of the square. Your points are then x = a, y = (height).

    Please be gentle, as it has been some time since I've used a lot of this math! :-)

提交回复
热议问题