How do I use rectint to find the area of two intersecting rectangles?

I am trying to find the area of two intersecting rectangles. The rectint function in the help file does not help demonstrate proper usage of the command.
I don't know the correct way to define the rectangles or use the command. I am also rotating one rectangle relative to the other, and the area is going to change. Both rectangles have the same center. I know the area should be at a max when the rectangles overlap and be at a min when the rectangles are at a right angles to each other. I can rotate the rectangles, but the area is not what I expect. What are the sins I have commited,and how to I atone for them? Some examples would be helpful.
A second challenge is to plot the the rectangles and the resulting area, but one problem at a time.

3 Comments

How can we possibly know what you have done wrong, if we cannot see what you have done? Yes, we could do your homework completely for you, but how will that really help you?
My appologies, I would not ask the community to solve my homework for me. If that is the impression, my mistake. I am working on project for work. To ask the community to do my homework for me would be abusing the community, and as you point out I would not learn anything useful.
I am playing with an idea in my off time.
Since you ask for better details...
x=-1:.1:1;
y=-1:.1:1;
a=meshgrid(x,y);% first rectangle
A=meshgrid(x,y); % second rectangle
B=rectint(a,A);
All I get is a matrix of 0's
I have also tried...
x=[-1 -1 2 3]
y=[-1 -1 2 3] % will get maximum area
to rotate x, I tried
x=[-1*cosd(15) -1*sind(15) 2 3]% first angle of rotation
the area is decreasing as expected, but am I roataing the angle correctly? I know at 90 degrees, I should have a min area of overlap and a max area at 0 degrees
I have used the rectint and the rotated the x rectangle from 0 to 360 degrees in 15 degree steps, and not sure the results are correct. I build a loop to from 0 to 360. I don't think I am doing this quite right.

Sign in to comment.

Answers (4)

maybe you get a first idea by looking at this:
http://csc.fsksm.utm.my/syed/projects/image-processing.html
The documentation you referred to does say clearly that a position vector is [x y w h] where x and y are the starting coordinates and w and h are the width and height.
Therefore for the purpose of this command, the rectangles must align with the x/y axes.
There is a set of polygon boolean operators in Mapping Toolbox. I can't find the official doc but the below link you an idea what you can do.
If you don't own the toolbox, there is a tool on FEX (haven't tried my self)
I have codded a Matlab based, if the above won't work, I probably could try to provide you part of my code.
Surprisingly, the help file is rather terse. Testing it out on a simple example, the x and y corner coordinates of the position vector need to be the lower right corner of the rectangle.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Asked:

on 9 Feb 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!