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