NB. geometrical graphics in OOP NB. revised Parsing PARA by parse_PA 2007/10/17 NB. revised Clear, newed display_point 2007/11/19 NB. parabola 2007/12/2 wr =: 1!:2&2 corequire 'user\Classes\pgeomgraph.ijs' run =: 3 : 0 ins =: '' conew 'pgeomgraph' run__ins '' ) reset =: 3 : 0 coerase conl 1 ) NB. (4, 2) range (2, 3) => 5 x 5 values centered at (2, 3) NB. 4 intervals of total width 2 NB. revised 2007/9/27 range =: 3 : 0 : ra =: (((-@-:) + i.@(>:)) % ]) ({.x.) px =: ({.y.) + ({:x.)*ra py =: ({:y.) + ({:x.)*ra |: (<"(0) px) (,L:0)/"(0 1) (<"(0) py) ) NB. (from;till) extract string => extracted string NB. PARA = 'ABC,P=R(circum)' NB. ('';',') extract PARA => ABC NB. (',';'=') extract PARA => P NB. ('=';'(') extract PARA => R NB. ('(';')') extract PARA => circum extract =: 3 : 0 : ('x0';'x1')=: x. y0 =. y. y1 =. (y0 i. x1){.y0 y2 =. (>: y1 i. x0)}.y1 ) NB. Parse PARA eg. 'ABC,P=R(circum)' 2007/10/17 parse_PA =: 3 : 0 : PARA =: y. select. x. case. 1 do. ('';',') extract PARA NB. ABC case. 2 do. (',';'=') extract PARA NB. P case. 3 do. ('=';'(') extract PARA NB. R case. 4 do. ('(';')') extract PARA NB. circum end. ) NB. Apollonius' Circle ===================================== apollo =: 3 : 0 A_A =: A_A__ins NB. global point data B_B =: B_B__ins NB. ,, 'm n ran int eps' =: parse COMMAND__ins P_P =: 0, 0 PP =: (int, ran) range P_P AP =: ap L:0 PP (> eps > L:0 ,AP) # ,PP ) NB. Apollonius Calculation ap =: 3 : 0 | (n*dis A_A - y.) - (m*dis B_B - y.) ) NB. Parse Command String NB. parse COMMAND__ins => m, n, ran, int, eps parse =: 3 : 0 PA0 =. y. m =. ". ('(';':') extract PA0 n =. ". (':';')') extract PA0 if. '=' e. PA0 do. ran =. ". ('=';',') extract PA0 NB. range if. ran = 0 do. ran =. 8 end. int =. ". (',';'/') extract PA0 NB. point of intervals if. int = 0 do. int =. 64 end. eps =. ". ('/';'') extract PA0 NB. epsilon if. eps = 0 do. eps =. 0.1 end. else. ran =. 8 int =. 128 eps =. 0.1 end. m, n, ran, int, eps ) NB. test program apo =: 3 : 0 PP =. y. A_A =: A_A__ins NB. global point data B_B =: B_B__ins NB. ,, AP =: ap L:0 PP MinXY =: > ({.@/: , >AP) { , PP MinV =: ({.@/: , >AP) { , > AP MinXY, MinV, ({:MinXY)%({.MinXY) ) NB. Parabola =============================================== parabola =: 3 : 0 A_A =: A_A__ins C_C =: C_C__ins D_D =: D_D__ins 'm n ran int eps' =: parse COMMAND__ins P_P =. 0, 0 PP =: (int, ran) range P_P AP =: parab L:0 PP (> eps > L:0 ,AP) # ,PP ) parab =: 3 : 0 P_P =. y. 'P_x P_y' =: P_P 'C_x C_y' =: C_C 'D_x D_y' =: D_D M =. (D_y - C_y)%(D_x - C_x) N =. C_y - C_x*(D_y -C_y)%(D_x - C_x) d_CD =: | ((-M*P_x)+ P_y +(-N))%(%: 1 + (-M)^2) NB. distance of P and CD d_A =: dis A_A - y. | d_CD - d_A ) NB. Ellipse and Hyperbola ================================== ellipse =: 3 : 0 A_A =: A_A__ins NB. global point data B_B =: B_B__ins NB. ,, 'm n ran int eps' =: parse COMMAND__ins P_P =: 0, 0 PP =: (int, ran) range P_P AP =: elip L:0 PP (> eps > L:0 ,AP) # ,PP ) elip =: 3 : 0 | m - (dis A_A - y.) + (dis B_B - y.) ) hyperbola =: 3 : 0 A_A =: A_A__ins NB. global point data B_B =: B_B__ins NB. ,, 'm n ran int eps' =: parse COMMAND__ins P_P =: 0, 0 PP =: (int, ran) range P_P AP =: hyp L:0 PP (> eps > L:0 ,AP) # ,PP ) hyp =: 3 : 0 | m - ((dis A_A - y.) - (dis B_B - y.)) ) NB. Lemniscate / 2008/12/20 =============================== lemniscate =: 3 : 0 A_A =: A_A__ins NB. global point data B_B =: B_B__ins NB. ,, 'm n ran int eps' =: parse COMMAND__ins P_P =: 0, 0 PP =: (int, ran) range P_P AP =: lemni L:0 PP (> eps > L:0 ,AP) # ,PP ) lemni =: 3 : 0 | m - (dis A_A - y.) * (dis B_B - y.) ) NB. if small character, then large character small_char =: 3 : 0 if. (96&< *. 123&>)@(a.&i.) y. do. ((_32&+) &. (a.&i.)) y. else. y. end. ) NB. Find Circum_center ==================================== NB. revised any parameters eg. XYZ,S=T(circum) using parse_PA NB. revised in call twice range and circ routine circum =: 3 : 0 P_P =: ". (2 parse_PA PARA__ins),'_',(2 parse_PA PARA__ins),'__ins' NB. P_P =: P_P__ins NB first search PP =: (8, 2) range P_P PP1 =: 2{. circ PP NB. second search PP2 =: (16, 1) range PP1 circ PP2 ) circ =: 3 : 0 PP =. y. A_A =: ". (0{1 parse_PA PARA__ins),'_',(0{1 parse_PA PARA__ins), '__ins' B_B =: ". (1{1 parse_PA PARA__ins),'_',(1{1 parse_PA PARA__ins), '__ins' C_C =: ". (2{1 parse_PA PARA__ins),'_',(2{1 parse_PA PARA__ins), '__ins' NB. A_A =: A_A__ins NB. global point data NB. B_B =: B_B__ins NB. ,, NB. C_C =: C_C__ins NB. ,, DIF =: dif L:0 PP MinXY =. > ({.@/: , >DIF) { , PP MinV =. ({.@/: , >DIF) { , > DIF MinXY, MinV ) dis =: %:@(+/@:*:) dif =: 3 : 0 a =: dis A_A - y. b =: dis B_B - y. c =: dis C_C - y. Dif =: | (a-b), (b-c), (c-a) +/ Dif ) NB. Inscribed Circle Center ================================= NB. 2007/9/26 incenter =: 3 : 0 P_P =: ". (2 parse_PA PARA__ins),'_',(2 parse_PA PARA__ins),'__ins' NB. P_P =: P_P__ins PP0 =: (8, 2) range P_P PP1 =: 2{. incen PP0 PP2 =: (16, 1) range PP1 incen PP2 ) incen =: 3 : 0 PP =. y. A_A =: ". (0{1 parse_PA PARA__ins),'_',(0{1 parse_PA PARA__ins), '__ins' B_B =: ". (1{1 parse_PA PARA__ins),'_',(1{1 parse_PA PARA__ins), '__ins' C_C =: ". (2{1 parse_PA PARA__ins),'_',(2{1 parse_PA PARA__ins), '__ins' NB. A_A =: A_A__ins NB. global point data NB. B_B =: B_B__ins NB. ,, NB. C_C =: C_C__ins NB. ,, calc_CM PP ) calc_C =: 3 : 0 LAB =. | ( (A_A;B_B) calc_L y.) LBC =. | ( (B_B;C_C) calc_L y.) LCA =. | ( (C_C;A_A) calc_L y.) +/ | (LAB-LBC), (LBC-LCA), (LCA-LAB) ) calc_CM =: 3 : 0 CM =: calc_C L:0 ,y. MinXY =. > (({.@/:) >CM) { , y. MinV =. (({.@/:){]) >CM MinXY, MinV ) NB. Center of Gravity ================================================= NB. Larson Problem/Graphical Solution ======================= NB. program called from pgeomgraph OOP gravity =: larson larson =: 3 : 0 P_P =: ". (2 parse_PA PARA__ins),'_',(2 parse_PA PARA__ins),'__ins' PP =: (8, 2) range P_P A_A =: ". (0{1 parse_PA PARA__ins),'_',(0{1 parse_PA PARA__ins), '__ins' B_B =: ". (1{1 parse_PA PARA__ins),'_',(1{1 parse_PA PARA__ins), '__ins' C_C =: ". (2{1 parse_PA PARA__ins),'_',(2{1 parse_PA PARA__ins), '__ins' NB. A_A =: A_A__ins NB. B_B =: B_B__ins NB. C_C =: C_C__ins PMax =: calc_LM PP ) NB. Larson subroutines calc_L =: 3 : 0 : 'a_a b_b'=: x. 'a_x a_y' =: a_a 'b_x b_y' =: b_b p_p =: y. 'p_x p_y' =: p_p M =. (b_y - a_y)%(b_x - a_x) N =. a_y - a_x*(b_y -a_y)%(b_x - a_x) D =. ((-M*p_x)+ p_y +(-N))%(%: 1 + (-M)^2) ) calc_M =: 3 : 0 LAB =. | ( (A_A;B_B) calc_L y.) LBC =. | ( (B_B;C_C) calc_L y.) LCA =. | ( (C_C;A_A) calc_L y.) LAB * LBC * LCA ) calc_LM =: 3 : 0 LM =. calc_M L:0 ,y. MaxXY =. > (({.@\:) >LM) { , y. MaxV =. (({.@\:){]) >LM MaxXY, MaxV ) NB. Larson =============================================