1 ! Copyright (C) 2008 Jeff Bigot
2 ! See http://factorcode.org/license.txt for BSD license.
28 ! ---------------------------------
29 : coord-min ( x array -- array ) swap suffix ;
30 : coord-max ( x array -- array ) swap neg suffix ;
32 : 4cube ( array name -- solid )
33 ! array : xmin xmax ymin ymax zmin zmax wmin wmax
39 [ { 1 0 0 0 } coord-min ] [ { -1 0 0 0 } coord-max ]
40 [ { 0 1 0 0 } coord-min ] [ { 0 -1 0 0 } coord-max ]
41 [ { 0 0 1 0 } coord-min ] [ { 0 0 -1 0 } coord-max ]
42 [ { 0 0 0 1 } coord-min ] [ { 0 0 0 -1 } coord-max ]
50 : 3cube ( array name -- solid )
51 ! array : xmin xmax ymin ymax zmin zmax wmin wmax
57 [ { 1 0 0 } coord-min ] [ { -1 0 0 } coord-max ]
58 [ { 0 1 0 } coord-min ] [ { 0 -1 0 } coord-max ]
59 [ { 0 0 1 } coord-min ] [ { 0 0 -1 } coord-max ]
68 : equation-system-for-normal ( points -- matrix )
69 unclip [ v- 0 suffix ] curry map
70 dup first [ drop 1 ] map suffix
73 : normal-vector ( points -- v )
74 equation-system-for-normal
75 intersect-hyperplanes ;
77 : points-to-hyperplane ( points -- hyperplane )
78 [ normal-vector 0 suffix ] [ first ] bi
81 : refs-to-points ( points faces -- faces )
82 [ swap [ nth 10 v*n { 100 100 100 } v+ ] curry map ]
85 ! V{ { 0.1 0.2 } { 1.1 1.3 } } V{ { 1 0 } { 0 1 } }
86 ! V{ { { 1.1 1.3 } { 0.1 0.2 } } { { 0.1 0.2 } { 1.1 1.3 } } }
88 : ply-model-path ( -- path )
95 : read-bunny-model ( -- v )
96 ply-model-path ascii [ parse-model ] with-file-reader
101 : 3points-to-normal ( seq -- v )
102 unclip [ v- ] curry map first2 cross normalize
104 : 2-faces-to-prism ( seq seq -- seq )
106 [ do-cycle 2 clump ] bi@ concat-nth
107 ! 3 faces rectangulaires
112 : Xpoints-to-prisme ( seq height -- cube )
113 ! from 3 points gives a list of faces representing
114 ! a cube of height "height"
115 ! and of based on the three points
116 ! a face is a group of 3 or mode points.
117 [ dup dup 3points-to-normal ] dip
118 v*n [ v+ ] curry map ! 2 eme face triangulaire
121 ! [ dup number? [ 1 + ] when ] deep-map
126 : Xpoints-to-plane4D ( seq x y -- 4Dplane )
127 ! from 3 points gives a list of faces representing
129 ! from x to y (height = y-x)
130 ! and of based on the X points
131 ! a face is a group of 3 or mode points.
132 '[ [ [ _ suffix ] map ] [ [ _ suffix ] map ] bi ] call
136 : 3pointsfaces-to-3Dsolidfaces ( seq -- seq )
137 [ 1 Xpoints-to-prisme [ 100
138 110 Xpoints-to-plane4D ] map concat ] map
142 : test-figure ( -- solid )
145 { 1 -1 -5 } cut-solid
146 { -1 -1 -21 } cut-solid
147 { -1 0 -12 } cut-solid