I have a rotate rectangle and I know the size of the diagonal. I also know the angle used to rotate the rectangl开发者_如何学编程e.
How can I calculate the width and height of the rectangle?
For a sketch of the problem, see:
1) create a new line starting at one of the end-points of the diagonal and travelling at the rotation angle.
2) project the other diagonal terminus onto this line. You now know one side of the rectangle.
3) Copy the segment to the other side of the diagonal and connect the endpoints to complete the rectangle.
The only 'tricky' code here is the projection. This webpage has some example code for Point-Line distance/projection: http://softsurfer.com/Archive/algorithm_0102/algorithm_0102.htm
Thanks David Rutten,
I got it working. Your site about the projection was to much for my math knowledge, but with some google i find a nice point to line intersection function which helped me to calc the length (distance) of one of the sides.
Unfortunately I'm too "new" here to award you with credits or reply on your anwser.
@Eric bainville: I knew the distance because i had point1 and point2 (upper left and bottom right) coordinates. With those coordinates it is possible. I didnt mention this, but luckily David guessed right that I knew them.
Thanks again!
精彩评论