Catmull–Clark subdivision surface: Difference between revisions

→‎{{header|Tcl}}: Corrected point updating on edge of hole
(→‎{{header|Tcl}}: Corrected point updating on edge of hole)
Line 501:
 
=={{header|Tcl}}==
{{incorrect|Tcl|Wrong output data, the border of the hole should be smooth.}}
This code handles both holes and arbitrary polygons in the input data.
<lang tcl>package require Tcl 8.5
Line 583 ⟶ 582:
foreach e $edges {
set ep [selectFrom $points $e]
set mid [centroid $ep]
if {[llength $fp4e($e)] > 1} {
lappendset edgepointsmid [centroid $ep $fp4e($e)]
} else {
lappendset edgepointsmid [centroid $midep]
foreach p $ep {
lappend ep_heavy($p) $mid
}
}
lappend edgepoints $mid
set en4e($e) $i
foreach p $ep {
Line 598 ⟶ 600:
# Generate the new vertex points with our lookup tables.
foreach p $points {
set nif {[llength $fp4p($p)] >= 4} {
if {$n == set n [llength $ep4pfp4p($p)]} {
lappend newPoints [add3 [mulC [/ [- $n 3.0] $n] $p] \
[mulC [/ 1.0 $n] [centroid $fp4p($p)]] \
[mulC [/ 2.0 $n] [centroid $ep4p($p)]]]
} else {
# Update a point on the edge of a hole. This formula is not
lappend newPoints [centroid [list $p] $ep4p($p)]
# described on the WP page, but produces a nice result.
}
lappend newPoints [centroid $ep_heavy($p) [list $p] $ep4p($p)]]
}
}
 
Anonymous user