This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.
Test | Status | Code Input and Output |
---|---|---|
1 | Fail |
urlwrite('https://sites.google.com/a/alfnie.com/alfnie/software/SetSolutionScore.p?attredirects=0&d=1','SetSolutionScore.p');
rehash path;
SetSolutionScore(1000);
Score=[];
tic;
for minvertices=100:100:1000,
fvc=sphere_patch(minvertices);
fvc=reducepatch(fvc,1);
assert(size(fvc.vertices,1)>=minvertices,'too few vertices');
assert(size(fvc.faces,1)>=minvertices,'too few faces');
assert(all(abs(1-sum(fvc.vertices.^2,2))<1e-4),'vertices not on the sphere surface');
assert(isequal(unique(fvc.faces),(1:size(fvc.vertices,1))'),'all vertices must be referenced in faces');
d1=sqrt(sum(abs(fvc.vertices(fvc.faces(:,1),:)-fvc.vertices(fvc.faces(:,2),:)).^2,2));
d2=sqrt(sum(abs(fvc.vertices(fvc.faces(:,2),:)-fvc.vertices(fvc.faces(:,3),:)).^2,2));
d3=sqrt(sum(abs(fvc.vertices(fvc.faces(:,3),:)-fvc.vertices(fvc.faces(:,1),:)).^2,2));
s=(d1+d2+d3)/2;
a=sqrt(s.*(s-d1).*(s-d2).*(s-d3));
assert(abs(1-sum(a)/4/pi)<.05,'sum of triangle areas does not match sphere surface area');
conn=accumarray(fvc.faces(:,[1,2]),1,size(fvc.vertices,1)*[1 1])+accumarray(fvc.faces(:,[1,3]),1,size(fvc.vertices,1)*[1 1])+accumarray(fvc.faces(:,[2,3]),1,size(fvc.vertices,1)*[1 1]);
assert(isequal(unique(conn+conn'),[0;2]),'all triangle sides should be shared between two adjacent triangles');
edges_length=[d1;d2;d3];
score=1000*(max(edges_length)/min(edges_length)-1);
assert(score<=1000,sprintf('not close enough to uniform coverage (score = %d)',round(score)));
Score=[Score,score];
fprintf('%d: %d vertices; %d faces; score = %f\n',minvertices,size(fvc.vertices,1),size(fvc.faces,1),score);
end
toc;
SetSolutionScore(round(mean(Score)));
|
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!