How to resolve the algorithm Faces from a mesh step by step in the zkl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Faces from a mesh step by step in the zkl programming language

Table of Contents

Problem Statement

A mesh defining a surface has uniquely numbered vertices, and named, simple-polygonal faces described usually by an ordered list of edge numbers going around the face,

For example: External image of two faces Rough textual version without edges: any of all the rotations of those ordered vertices. of their rotations. Let's call the above the perimeter format as it traces around the perimeter. A separate algorithm returns polygonal faces consisting of a face name and an unordered set of edge definitions for each face. ascending order. For example face A could be described by the edges (1, 11), (7, 11), and (1, 7) (The order of each vertex number in an edge is ascending, but the order in which the edges are stated is arbitrary). Similarly face B could be described by the edges (11, 23), (1, 17), (17, 23), and (1, 11) in arbitrary order of the edges. Let's call this second format the edge format.

  1. Write a routine to check if two perimeter formatted faces have the same perimeter. Use it to check if the following pairs of perimeters are the same:
  2. Write a routine and use it to transform the following faces from edge to perimeter format. Show your output here.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Faces from a mesh step by step in the zkl programming language

Source code in the zkl programming language

fcn perimSame(p1, p2){
   if(p1.len() != p2.len()) return(False);
   False == p1.filter1('wrap(p){ (not p2.holds(p)) })
}

fcn edge_to_periphery(faces){
   edges:=faces.copy().sort(fcn(a,b){ if(a[0]!=b[0]) a[0]
   p,last := ( if(edges) edges.pop(0).copy() else T ), ( p and p[-1] or Void );
   while(edges){
      foreach i,j in (edges){
         if     (i==last){ p.append( last=j ); edges.del(__iWalker.idx); break; }
         else if(j==last){ p.append( last=i ); edges.del(__iWalker.idx); break; }
      }
      fallthrough{ return(">>>Error! Invalid edge format<<<") }
   }
   p[0,-1]	// last element not part of result
}

println("Perimeter format equality checks:");
ps:=T( T( T(8,1,3), T(1,3,8) ), 
       T( T(18, 8, 14, 10, 12, 17, 19), T(8, 14, 10, 12, 17, 19, 18) ) );
foreach p1,p2 in (ps)
   { println(pp(p1), "  equivalent to  ", pp(p2), "? ", perimSame(p1,p2)) }

println("\nEdge to perimeter format translations:");
edge_d:=T(
        T(T( 1, 11), T( 7, 11), T( 1,  7) ),
        T(T(11, 23), T( 1, 17), T(17, 23), T( 1, 11) ),
        T(T( 8, 14), T(17, 19), T(10, 12), T(10, 14), T(12, 17), T(8, 18), T(18, 19) ),
        T(T( 1,  3), T( 9, 11), T( 3, 11), T( 1, 11) ),
        );
foreach  edges in (edge_d)
   { println(ppp(edges), "  --> ", edge_to_periphery(edges)) }

fcn pp(a){ a.concat(", ","(",")") }
fcn ppp(edges){ pp(edges.apply(pp)) }

  

You may also check:How to resolve the algorithm The Name Game step by step in the Fōrmulæ programming language
You may also check:How to resolve the algorithm Fixed length records step by step in the Pascal programming language
You may also check:How to resolve the algorithm Sort an array of composite structures step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Literals/String step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Generic swap step by step in the Plain English programming language