0% found this document useful (0 votes)
48 views2 pages

Prompt 'The Farthest Vertex of The Rectangle (X Y) :'

The document defines variables to represent the vertices of a rectangle based on user input of its farthest point and calculates the distance from an outside point to divide rectangles within the shape. It then iterates through the rectangles, calculating the distance to the outside point for each and summing the inverse distances to get a total value returned at the end.

Uploaded by

Victor Daggers
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views2 pages

Prompt 'The Farthest Vertex of The Rectangle (X Y) :'

The document defines variables to represent the vertices of a rectangle based on user input of its farthest point and calculates the distance from an outside point to divide rectangles within the shape. It then iterates through the rectangles, calculating the distance to the outside point for each and summing the inverse distances to get a total value returned at the end.

Uploaded by

Victor Daggers
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

clear all

clc

prompt = 'The farthest vertex of the rectangle [x y]:'

prompt =
'The farthest vertex of the rectangle [x y]:'

c = input(prompt);
prompt = 'Specify first arbitrary point outside the rectangle [x y z]'

prompt =
'Specify first arbitrary point outside the rectangle [x y z]'

q = input(prompt);

a = [0 0];
b = [c(1) 0];
d = [0 c(2)];

display(a);

a = 1×2
0 0

display(b);

b = 1×2
10 0

display(c);

c = 1×2
10 6

display(d);

d = 1×2
0 6

rectangle('Position',[0 0 c(1) c(2)]);

X = 0:1:c(1);
Y = 0:1:c(2);

display(X);

X = 1×11
0 1 2 3 4 5 6 7 8 9 10

display(Y);

Y = 1×7
0 1 2 3 4 5 6

I = 0;
for i = X(1) : X(c(1))

1
for j = Y(1) : Y(c(2))
rectangle('Position',[i j 1 1]);
x1 = -(i-(i-1)/(2*sqrt(3)))+((i+(i+1))/2);
x2 = (i-(i-1)/(2*sqrt(3)))+((i+(i+1))/2);
y1 = -(j-(j-1)/(2*sqrt(3)))+((j+(j+1))/2);
y2 = (j-(j-1)/(2*sqrt(3)))+((j+(j+1))/2);
d1 = sqrt((q(1)-x1)^2 + (q(2)-y1)^2 + (q(3)^2));
d2 = sqrt((q(1)-x2)^2 + (q(2)-y2)^2 + (q(3)^2));
f1 = 1/d1;
f2 = 1/d2;
f = 0.5*(f1 + f2);
I = I + f;
end
end

display(I);

I = 0.9941

You might also like