1 view (last 30 days)

Consider four square shaped ranches arranged in a 2x2 grid. One family lives on each ranch and each family builds a small house independently at a random spot within their property. The families then construct 4 straight line paths between the houses that go across property lines. The path forms a quadrilateral circuit path connecting all four houses which also serves as a boundary in which their children can play. What is the probability that their children can travel in a straight line between any two points without leaving the boundary? In other words, what is the probability that the boundary is a convex quadrilateral?

This is what I managed to do.

I am struggling to calculate the probability. How do I calculate the probability. Thank you in advance.

P=[0 0; 1 1; 1.5 0.5; 1.5 -0.5; 2 0];

[k,av]=convhull(P);

plot(P(:,1),P(:,2),'*')

hold on

plot(P(k,1),P(k,2))

Rik
on 12 Oct 2020

If you want to do a Monte-Carlo-style simulation, I would suggest using rand to generate the coordinates. I would suggest putting the center of the four ranches at (0,0), so you can use the sign of either coordinate to easily generate all coordinates.

Given that this is homework: show what you have done to implement this and I might be able to give you some more specific advice.

Image Analyst
on 12 Oct 2020

Rik
on 12 Oct 2020

Image Analyst
on 13 Oct 2020

Here is an example of a Monte Carlo simulation:

clc; % Clear the command window.

close all; % Close all figures (except those of imtool.)

clear; % Erase all existing variables. Or clearvars if you want.

workspace; % Make sure the workspace panel is showing.

format long g;

format compact;

fontSize = 22;

fprintf('Beginning to run %s.m ...\n', mfilename);

xy=[-2 -0.25;

0 -0.5;

2 -0.27;

0 -0.35;

-2 -0.25;...

];

plot(xy(:,1), xy(:,2), 'b.-', 'MarkerSize', 40, 'LineWidth', 2)

grid on;

[hullIndexes,av] = convhull(xy);

xyCH = xy(hullIndexes,:)

hold on

plot(xyCH(:,1), xyCH(:,2), 'r-', 'LineWidth', 2)

title('Original in blue, Convex hull in red.', 'FontSize', 20);

numTrials = 4000

originalCount = 0;

numHouses = size(xy, 1);

for k = 1 : numTrials

% Get two random house locations

indexes2 = randperm(numHouses, 2);

% Get xy of first house.

x1 = xy(indexes2(1), 1);

y1 = xy(indexes2(1), 2);

% Get xy of second house.

x2 = xy(indexes2(2), 1);

y2 = xy(indexes2(2), 2);

% Get midpoint of the line.

xMid = mean([x1, x2]);

yMid = mean([y1, y2]);

% See if the midpoint lies inside or outside of the original shape.

% It will be guaranteed to lie within the convex hull so we don't need to check that.

inOriginal = inpolygon(xMid, yMid, xy(:, 1), xy(:, 2));

if inOriginal

% Plot green line.

% plot([x1, x2], [y1, y2], 'g-', 'LineWidth', 2);

originalCount = originalCount + 1;

fprintf('Trial #%d of %d is inside the shape.\n', k, numTrials);

else

% Plot red line.

% plot([x1, x2], [y1, y2], 'r-', 'MarkerSize', 16);

fprintf('Trial #%d of %d is outside the shape.\n', k, numTrials);

end

end

% Get proportion of total trials inside the original shape.

pInShape = originalCount / numTrials

% Get proportion of total trials outside the original shape.

pOutsideShape = (numTrials - originalCount) / numTrials

g = gcf;

g.WindowState = 'maximized'

fprintf('Done running %s.m ...\n', mfilename);

You'll get:

pInShape =

0.8105

pOutsideShape =

0.1895

Opportunities for recent engineering grads.

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

Start Hunting!
## 2 Comments

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/611406-what-is-the-probability-that-their-children-can-travel-in-a-straight-line-between-any-two-points-wit#comment_1053926

⋮## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/611406-what-is-the-probability-that-their-children-can-travel-in-a-straight-line-between-any-two-points-wit#comment_1053926

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/611406-what-is-the-probability-that-their-children-can-travel-in-a-straight-line-between-any-two-points-wit#comment_1054601

⋮## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/611406-what-is-the-probability-that-their-children-can-travel-in-a-straight-line-between-any-two-points-wit#comment_1054601

Sign in to comment.