Apl2ToDoNumericalGeometryAlgorithms
This is a sub-page of PhraseBook/ToDo/Apl2Idioms
ZA←AXׯ12○○AY÷180 ⍝ From magnitude AX and degrees AY to complex.
ZA←AXׯ12○AY ⍝ From magnitude AX and radians AY to complex.
NA←|0J1⊥⊖A ⍝ Get magnitude of A. 2=↑⍴A (x,y) pairs
NA←|AX+¯11○AY ⍝ Get magnitude of real AX and imaginary AY.
NA←12○0J1⊥⊖A ⍝ Get angle in radians of A. 2=↑⍴A (x,y) pairs
NA←12○AX+¯11○AY ⍝ Get angle (rad) of real AX and imaginary AY.
NA←(180÷○1)×12○0J1⊥⊖A ⍝ Get angle in degrees of A. 2=↑⍴A (x,y) pairs
NA←(180÷○1)×12○AX+¯11○AY ⍝ Get angle (deg) of real AX and imaginary AY.
NA←9 11∘.○ZA ⍝ Split complex array into real & imaginary.
ZA←AX+¯11○AY ⍝ Join XA real and YA imaginary to complex.
ZA←(9○ZAX)+¯11○11○ZAY ⍝ Real from ZAX and imaginary from ZAX.
ZA←¯11○+ZA ⍝ Swap real & imaginary.
S←+/|2-/Z ⍝ Length of polygon.
ZA←ZA+6J9 ⍝ Move figure by x=6, y=9.
ZA←ZA×1D30 ⍝ Rotate figure 30 degrees.
ZA←ZA××ZS ⍝ Rotate figure in direction of point ZS.
ZA←ZA×2.1 ⍝ Isometric scaling by 2.1.
ZA←ZA×2.1D30 ⍝ Rotate & scale at same time.
ZA←(2,¯11○3)+.×9 11∘.○ZA ⍝ Rectangular scale by x=2,y=3.
ZA←ZA+¯11○.3×9○ZA ⍝ Skew by 30 percent in y.
ZA←+ZA ⍝ Mirror in X.
ZA←-+ZA ⍝ Mirror in Y.
ZA←(¯10+~BA)○ZA ⍝ Mirror in X if B.
VZA←,¨ZA ⍝ Pinpoint figure rather than polygon.
Z←*○0J2×(⍳NS+1)÷NS ⍝ Regular unit polygon of NS edges.
Z←*○0J2×(0,⍳NS)÷NS ⍝ Regular unit polygon of NS edges.
VZ←0,¨*○0J2×(1+⍳NS)÷NS ⍝ NS spokes of unit wheel.
VZ←0,¨*○0J2×(⍳NS)÷NS ⍝ NS spokes of unit wheel.
V←×11○(ZS-1↓Z)×+2-/Z ⍝ Sign of point ZS relative to edges of Z.
Z←(⍳5)∘.+¯11○⍳10 ⍝ All pixels in a 5 by 10 window.
Z←V+¯11○f V ⍝ Plot of scalaroid function 'f' for data V.
Z←0J1⊥1 0⌽2/⊃V(⍳1+⍴V) ⍝ Outline of bar chart of data V.
Z←0J1⊥1 0⌽2/0,⊃V(⍳⍴V) ⍝ Outline of bar chart of data V.
Z←¯3↓,Z-[0]((2-/Z÷3),0)∘.×0 1,(1+1D60),2 ⍝ Koch island new generation.
Z←¯3↓,Z-[1]((2-/Z÷3),0)∘.×0 1,(1+1D60),2 ⍝ Koch island new generation.
VZ←(⊂ZX)+(⊂ZY-ZX)×(⍳NS+1)÷NS ⍝ Cascade NS-fold fill between two polygons.
VZ←(⊂ZX)+(⊂ZY-ZX)×(0,⍳NS)÷NS ⍝ Cascade NS-fold fill between two polygons.
M←2 2⊤1+⍳4 ⍝ Unit square.
M←2 2⊤⍳4 ⍝ Unit square.
M←2 2 2⊤1+⍳8 ⍝ Unit cube.
M←2 2 2⊤⍳8 ⍝ Unit cube.
M←2 2 2 2⊤1+⍳16 ⍝ Unit tesseract.
M←2 2 2 2⊤⍳16 ⍝ Unit tesseract.
Z←0J1⊥M[1 0;] ⍝ Parallel projection of 3D object in M.
Z←0J1⊥M[2 1;] ⍝ Parallel projection of 3D object in M.
Z←0J1⊥M[1 0;]×D÷D-M[2;] ⍝ Perspective projection from distance D.
Z←0J1⊥M[2 1;]×D÷D-M[3;] ⍝ Perspective projection from distance D.
VZ←(¯.5 .5×NS)+⊂Z ⍝ Stereo pair. (Eye separation NS)
Z←0J1⊥0 1⌽2/|⌊/M,[0.5]-M←11 9∘.○Z⍝ Window enclosing Z.
Z←0J1⊥0 1⌽2/|⌊/M,[1.5]-M←11 9∘.○Z⍝ Window enclosing Z.
Z←(,[⍳0](1+⍳NS)÷NS)⊥M+.×Z ⍝ NS-point spline.(M=Bezier matrix, Z ctrl pts)
Z←(,[⍳0](⍳NS)÷NS)⊥M+.×Z ⍝ NS-point spline.(M=Bezier matrix, Z ctrl pts)
V←(×/(+/X÷2)-0,X)*.5 ⍝ Area of a triangle given side length. 3=⍴X
NS←|.5×+/Y×(¯1⌽X)-1⌽X ⍝ Area of a polygon given X,Y endpoints.
A←10 12∘.○ZA ⍝ From complex to magnitude and radians. 2=↑⍴A
AV←AX∘.,AY ⍝ Cartesian product: all pairs of AX, AY.
APL Wiki