Results 1 to 2 of 2

Thread: Calculate points within a rotated rectangle

  1. #1
    Jan 2017

    Calculate points within a rotated rectangle

    I have an app that I am working on. A bitmap will have a rectangle drawn on it. I need to rotate the rectangle anywhere from 0 - 360 degrees along its center point. After the rectangle is rotated I need to calculate if any given point int the picture falls inside the rectangle. All distances in centimeters. Looking for a good way to calculate using the following inputs:

    bitmap width - width of the whole image
    bitmap height - height of the whole image
    rectangle width - width of the rectangle drawn
    rectangle height - height of the rectangle drawn
    angle of rotation - rotated clockwise 360 degrees

    The point that is given can be expressed as an x,y position from the top left corner of the bitmap or a distance from the center of the rectangle
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Senior Member
    Jan 2009

    Re: Calculate points within a rotated rectangle

    Here is a sketch of what I'd do in your case. The first thing I did was solve for the base case, where there is no rotation. I then convinced myself that being within the boundary of a region would be retained with a rotation.
    So if I have a clockwise rotated rectangle of \theta, I counterclockwise rotate it back that much in my calculations. It's not elegant to show all the work, but I hope this leads you on the right track.
    |*| denotes absolute value.

    Calculate points within a rotated rectangle-sketch.png

    Given O is the origin (0,0)
    No rotations : verify P(x,y) |x| < 1/2 w and |y| < 1/2 h. If not, it's not within the boundary.

    With a rotation clockwise of an angle \theta, use a rotation matrix to rotate counterclockwise, then solve,

    Verify that P'(x',y'), the transformed point corresponding to P(x,y) follows the below rules. If it does, then P in within the boundary of your rotated rectangle.

    |x'| = |x\cos(\theta) - y\sin(\theta)| < 1/2 w
    |y'| = |x\sin(\theta) + y\cos(\theta)| < 1/2 h
    Last edited by MacstersUndead; Jan 28th 2017 at 05:05 PM.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. how to determine rotated rectangle offset
    Posted in the Geometry Forum
    Replies: 3
    Last Post: Jan 10th 2014, 08:14 AM
  2. Replies: 2
    Last Post: Jun 28th 2012, 06:07 AM
  3. Replies: 6
    Last Post: Jun 2nd 2011, 04:56 PM
  4. Replies: 2
    Last Post: Jul 8th 2009, 01:12 PM
  5. Rotated rectangle
    Posted in the Trigonometry Forum
    Replies: 3
    Last Post: Apr 22nd 2008, 01:21 PM

/mathhelpforum @mathhelpforum