Catmull–Clark subdivision surface: Difference between revisions
Content added Content deleted
(move the "Capability:" part into the template.) |
(tentative J implementation) |
||
Line 42: | Line 42: | ||
For edges and vertices not next to a hole, the standard algorithm from above is used. |
For edges and vertices not next to a hole, the standard algorithm from above is used. |
||
=={{header|J}}== |
|||
<lang j>havePoints=: e."1/~ i.@# |
|||
catmullclark=:3 :0 |
|||
'mesh points'=.y |
|||
face_point=: avg"2 mesh{points |
|||
point_face=: |: mesh havePoints points |
|||
avg_face_points=: point_face avg@#"1 2 face_point |
|||
edges=: ~.,/meshEdges=:mesh /:~@,"+1|."1 mesh |
|||
edge_point=: avg"2 edges{points |
|||
point_edge=: |: edges havePoints points |
|||
avg_mid_edges=: point_edge avg@#"1 2 edge_point |
|||
n=: +/"1 point_edge |
|||
'm3 m2 m1'=:(2,1,:n-3)%"1 n |
|||
new_coords=: (m1 * points) + (m2 * avg_face_points) + (m3 * avg_mid_edges) |
|||
pts=: face_point,edge_point,new_coords |
|||
c0=:(#edge_point)+e0=:#face_point |
|||
msh=:(,c0+mesh),.(,e0+edge i. meshEdges),.((#i.)~/$mesh),.,e0+_1|."1 edge i. meshEdges |
|||
msh;pts |
|||
)</lang> |
|||
Example use: |
|||
<lang j>NB.cube |
|||
points=: _1+2*#:i.8 |
|||
mesh=:1 A."1 I.(,1-|.)8&$@#&0 1">4 2 1 |
|||
catmullclark mesh;points |
|||
┌──────────┬─────────────────────────────┐ |
|||
│22 6 0 9│ 1 0 0│ |
|||
│23 7 0 6│ 0 1 0│ |
|||
│25 8 0 7│ 0 0 1│ |
|||
│24 9 0 8│ 0 0 _1│ |
|||
│20 10 1 12│ 0 _1 0│ |
|||
│21 11 1 10│ _1 0 0│ |
|||
│25 8 1 11│ 1 _1 0│ |
|||
│24 12 1 8│ 1 0 1│ |
|||
│19 13 2 14│ 1 1 0│ |
|||
│21 11 2 13│ 1 0 _1│ |
|||
│25 7 2 11│ _1 1 0│ |
|||
│23 14 2 7│ 0 1 1│ |
|||
│18 15 3 16│ 0 1 _1│ |
|||
│20 12 3 15│ _1 0 1│ |
|||
│24 9 3 12│ 0 _1 1│ |
|||
│22 16 3 9│ _1 0 _1│ |
|||
│18 17 4 16│ 0 _1 _1│ |
|||
│19 14 4 17│ _1 _1 0│ |
|||
│23 6 4 14│_0.555556 _0.555556 _0.555556│ |
|||
│22 16 4 6│_0.555556 _0.555556 0.555556│ |
|||
│18 17 5 15│_0.555556 0.555556 _0.555556│ |
|||
│19 13 5 17│_0.555556 0.555556 0.555556│ |
|||
│21 10 5 13│ 0.555556 _0.555556 _0.555556│ |
|||
│20 15 5 10│ 0.555556 _0.555556 0.555556│ |
|||
│ │ 0.555556 0.555556 _0.555556│ |
|||
│ │ 0.555556 0.555556 0.555556│ |
|||
└──────────┴─────────────────────────────┘</lang> |
|||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |