Cody

Problem 1935. Spherical surface triangulation

Solution 333912

Submitted on 15 Oct 2013 by Tim
  • Size: 191
  • This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
urlwrite('https://sites.google.com/a/alfnie.com/alfnie/software/SetSolutionScore.p?attredirects=0&amp;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)));

100: 162 vertices; 320 faces; score = 177.652828 200: 642 vertices; 1280 faces; score = 190.652166 300: 642 vertices; 1280 faces; score = 190.652166 400: 642 vertices; 1280 faces; score = 190.652166 500: 642 vertices; 1280 faces; score = 190.652166 600: 642 vertices; 1280 faces; score = 190.652166 700: 2562 vertices; 5120 faces; score = 193.992426 800: 2562 vertices; 5120 faces; score = 193.992426 900: 2562 vertices; 5120 faces; score = 193.992426 1000: 2562 vertices; 5120 faces; score = 193.992426 Elapsed time is 2.207867 seconds.

Suggested Problems

More from this Author38

Community Treasure Hunt

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

Start Hunting!