I am trying to solve the problem for my assignment that have polygon Q as input and outputs polygon P such that 2D coordinate points of Q are midpoints of the polygon P.
That is, given a sequence of k points in the plane q1...qk, find a sequence p1...pk such that
q1 is the midpoint of p1 and p2
q2 is the midpoint of p2 and p3
...
qk is the midpoint of p1 and pk.
I wrote the function in Matlab that handles the scenario for an odd number of k points. However, it does not work for an even number of k points.
function [P,FOUND] = InvertMidpoints(Q)
C=zeros(length(Q));
P=zeros(2,length(Q));
FOUND=false;
k=1;
x=[Q(1,:)]';
y=[Q(2,:)]';
if mod(length(Q),2)==0
disp('Did not solve for even number of points')
else
for i=1:(length(Q)-1)
C(i,k)=1/2;
C(i,k+1)=1/2;
k=k+1;
i=i+1;
end
C(length(Q),1)=1/2;
C(length(Q),length(Q))=1/2;
a=linsolve(C,x);
b=linsolve(C,y);
P(1,:)=a;
P(2,:)=b;
FOUND=true;
end
end
Basically, it solves linear equations with a C matrix of coefficients.
My professor provided me the following hint, but I really didn't get it:
The matrix C is always of rank k if k is odd and of rank k − 1 if k is even. So if k is odd then you can just construct the above matrix and solve the problem. If k is even, then Matlab won’t allow you to do that, even if there is a solution. Rather you have to (a) throw out one of the equations; (b) solve the remaining set of k − 1 equations in k unknowns; (c) check to see whether the solution you have found satisfies the last equation
Please, can you explain to me what that hint really means? Thanks!