To find common area between two plots.

11 views (last 30 days)
Sanjana Dhiran
Sanjana Dhiran on 19 Jul 2018
Answered: Caleb Williams on 19 Jul 2018
Hello everyone, I want to find the common area between a circle whose diameter endpoints' coordinates are known and a curve formed by a set of 175 points. How to do that??

Answers (1)

Caleb Williams
Caleb Williams on 19 Jul 2018
The first step is to turn your circle into an array of points.
theta=0:0.001*pi:2*pi;
x=cos(theta');
y=sin(theta');
The plot both the circle points and the curve's points (175x2 array named "curve") on the same figure (for visuals).
plot(x,y,'b*',curve(:,1),curve(:,2),'r*');
Now from here, you'll have two regions of the circle/curve - you've got to pick which one you want to find the area of. But once you figure that portion out, you could use a nearest neighbor search (see "knnsearch") to find the nearest neighbor in the circle to the curve. Find the elements of the curve where that distance is a minimum and then eliminate all elements outside of those.
[element,distance]=knnsearch([x y],curve);
% Find two elements in curve that have the minimum distance to [x y].
% Call them element 'a' and element 'b' (in ascending order).
curve=curve(a:b,:); % eliminates portion of curve outside of circle
Then you're going to find the area inside of the polygonal region formed by the circle and this portion of the curve. You can use MATLAB's built in "polyarea" function.

Categories

Find more on Computational Geometry in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!