September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,39 +0,0 @@
mag =: +/&.:*:"1
norm=: %"1 0 mag
dot =: +/@:*"1
NB. (pos;posr;neg;negr) getvec (x,y)
getvec =: 4 :0 "1
pt =. y
'pos posr neg negr' =. x
if. (dot~ pt-}:pos) > *:posr do.
0 0 0
else.
zb =. ({:pos) (-,+) posr -&.:*: pt mag@:- }:pos
if. (dot~ pt-}:neg) > *:negr do.
(pt,{:zb) - pos
else.
zs =. ({:neg) (-,+) negr -&.:*: pt mag@:- }:neg
if. zs >&{. zb do. (pt,{:zb) - pos
elseif. zs >&{: zb do. 0 0 0
elseif. ({.zs) < ({:zb) do. neg - (pt,{.zs)
elseif. do. (pt,{.zb) - pos end.
end.
end.
)
NB. (k;ambient;light) draw_sphere (pos;posr;neg;negr)
draw_sphere =: 4 :0
'pos posr neg negr' =. y
'k ambient light' =. x
vec=. norm y getvec ,"0// (2{.pos) +/ i: 200 j.~ 0.5+posr
b=. (mag vec) * ambient + k * 0>. light dot vec
)
togray =: 256#. 255 255 255 <.@*"1 0 (%>./@,)
env=.(2; 0.5; (norm _50 30 50))
sph=. 20 20 0; 20; 1 1 _6; 20
'rgb' viewmat togray env draw_sphere sph

View file

@ -1,54 +0,0 @@
load'graphics/viewmat'
resolution=: 8
spheres=: 3 1 #"1 ] 0 1,_1 1,:0.3 0.6 NB. spheres x y z r
coordinates=: (% <:)~ (,"1 0~"0 3 ,"0"1 0~)@:i:
length=: +/ &.: *:
centers=: _ 3&{.
radii=: _ _1&{.
NB. resolution SlicePittedSphere spheres generates a binary array, 1 in the geometric object
SlicePittedSphere=: (0 { {. > [: +./ }.)@:(radii@[ >:"0 3 ((length@:-"1"_ 1 centers)~ coordinates))~
spanTo=: conjunction def '(m<:y)*.y<:n' NB. algebraic similarity, m <= y <= n
tessellate=: ] ];._3"3~ 3 # [ NB. All cubical edge length x subarrays of array y
NB. Define "faces" as those points with 9 to 18 inclusive "solid" neighbors.
detectFace=: (9 spanTo 18) @: (+/@:,"3) @: (3&tessellate)
NB. arrange faces in ANSYS brick face order
ThickFaces=: ((|:"3 , (, |:"2))(,: |."1)3 3 3$2j1#1) /: 'SENWDU' i. 'DUEWSN'
ThinFaces=: ((|:"3 , (, |:"2))(,: |."1)3 3 3$1j2#1) /: 'SENWDU' i. 'DUEWSN'
FACES=:ThickFaces NB. 6 below comes from #Faces
NORMALS=: 2 tessellate FACES
matchNormals=: [: +/@,"6 NORMALS ="6"6 _ (2 tessellate 3 tessellate ])
bestFit=: (i.>./)"1&.|:
topFace=: detectFace i:"1 1:
choose=: 4 : 'x}y'
viewmat resolution (topFace choose (,&(#FACES))@:bestFit@matchNormals)@SlicePittedSphere spheres
<"_1 ThickFaces NB. display the 6 cubes with reference faces
┌─────┬─────┬─────┬─────┬─────┬─────┐
│1 1 1│1 1 0│0 0 0│0 1 1│1 1 1│0 0 0│
│1 1 1│1 1 0│1 1 1│0 1 1│1 1 1│0 0 0│
│0 0 0│1 1 0│1 1 1│0 1 1│1 1 1│0 0 0│
│ │ │ │ │ │ │
│1 1 1│1 1 0│0 0 0│0 1 1│1 1 1│1 1 1│
│1 1 1│1 1 0│1 1 1│0 1 1│1 1 1│1 1 1│
│0 0 0│1 1 0│1 1 1│0 1 1│1 1 1│1 1 1│
│ │ │ │ │ │ │
│1 1 1│1 1 0│0 0 0│0 1 1│0 0 0│1 1 1│
│1 1 1│1 1 0│1 1 1│0 1 1│0 0 0│1 1 1│
│0 0 0│1 1 0│1 1 1│0 1 1│0 0 0│1 1 1│
└─────┴─────┴─────┴─────┴─────┴─────┘