First draft of the projected-Bezier closed-curve inside-testing ray tracer.
Unfortunately there are no rays yet. And no tracing. And no output, either (but it did stop crashing!).
%!
(
mat.ps) run
[
/n 10
/Cam [0 0 -10]
/Eye [0 0 -10]
/Rot 3 ident
>>begin
[
/proj {
Cam {sub} vop % translate to camera coords
Rot matmul % perform camera rotation
0 get % extract vector from 1x3 matrix
aload pop Eye aload pop % extract dot x,y,z and eye xyz
4 3 roll div exch neg % perform perspective projection
4 3 roll add 1 index mul
4 1 roll 3 1 roll sub mul exch % (ez/dz)(dx-ex) (ez/dz)(dy-ey)
exch
} bind def
/eval-bezier{ % [curve]
dup { v 0 get } forall
4 array astore 1 array astore transpose
TN exch matmul 0 get 0 get exch
dup { v 1 get } forall
4 array astore 1 array astore transpose
TN exch matmul 0 get 0 get exch
{ v 2 get } forall
4 array astore 1 array astore transpose
TN exch matmul 0 get 0 get
3 array astore
}
/N[[-1 3 -3 1][3 -6 3 0][-3 3 0 0][1 0 0 0]]
/t-array { % t
dup dup mul % t t^2
2 copy mul % t t^2 t^3
3 1 roll exch 1 4 array astore % [t^3 t^2 t 1]
}
/v{vert exch 1 sub get}
/tok{token pop exch pop}
/s{(,){search{tok 3 1 roll}{tok exit}ifelse}loop}
/readlist{token pop{[f 100 string readline pop s]}repeat}
/f(teapot)(r)file
>>begin currentdict{dup type/arraytype eq
1 index xcheck
and{bind def}{pop pop}ifelse}forall
/patch [ f readlist ] def
/vert [ f readlist ] def
patch {
/p exch def
p 0 get v proj moveto
p 4 get v proj p 8 get v proj p 12 get v proj curveto
0 1 n div 1 {
dup /t exch def
t-array /T exch def
/TN T N matmul def
gsave
p 12 4 getinterval eval-bezier proj moveto
p 8 4 getinterval eval-bezier proj
p 4 4 getinterval eval-bezier proj
p 0 4 getinterval eval-bezier proj curveto
closepath
%Check Point Here
grestore
} for
} forall