Find the number of trapeziums that it can be formed with the vertices of a regular polygon.
After trying various formulas involving combinations, and mulltiplications by the n-fold symmetry and trying to subtract out the rectangles, which would otherwise be counted twice, and differentiating odd n from even n, I gave up trying to find a formula.
The program keeps track of the slope of every line, identifying each line by the ID of its two defining points (ID being the subscript on the table of point coordinates).
That table of slopes is sorted to find all pairs of lines with matching slope; each such map goes onto a table of quadrilaterals, which are all trapezoids. Duplicates are discarded and unique sets of four points remain. This set is counted and reported.
clearvars,clc
for n=4:15
pts=double.empty(0,2); % x,y
incr=360/n;
for a=.1:incr:360-incr+.2
pts(end+1,:)=[cosd(a),sind(a)];
end
lines=double.empty(0,3); % v1,v2,slope
for v1=1:n
for v2=v1+1:n
slope=(pts(v2,2)-pts(v1,2))/(pts(v2,1)-pts(v1,1));
lines(end+1,:)=[v1,v2,slope];
end
end
lines=sortrows(lines,3);
quad=double.empty(0,4);
for l1=1:size(lines,1)
for l2=l1+1:size(lines,1)
if abs(lines(l1,3)-lines(l2,3))<abs((1e-10)*lines(l2,3))
quad(end+1,:)=sort([lines(l1,1) lines(l1,2) lines(l2,1) lines(l2,2)]);
end
end
end
quad=unique(quad,'rows');
fprintf('%3d %4d\n',n,size(quad,1))
end
finding the numbers:
n trapezoids from
n-gon vertices
4 1
5 5
6 9
7 21
8 30
9 54
10 70
11 110
12 135
13 195
14 231
15 315
|
Posted by Charlie
on 2024-04-12 14:45:40 |