NB. Inversion Geometry Graphics NB. J4\user\inversion2.ijs by T.N 2019/9/5 wr =: 1!:2&2 load 'trig' load 'gl2' INVERGRAPH=: 0 : 0 pc invergraph;pn "Inversion Geometry"; menupop "File"; menu new "&New" "" "" ""; menu open "&Open" "" "" ""; menusep ; menu exit "&Exit" "" "" ""; menupopz; xywh 315 5 34 12;cc cancel button;cn "Exit"; xywh 12 12 205 166;cc invgraph isigraph; xywh 224 23 24 10;cc label static;cn "(X, Y)"; xywh 253 21 40 11;cc inxy edit ws_border es_autohscroll; xywh 301 23 9 10;cc label static;cn "R"; xywh 310 21 37 11;cc inr edit ws_border es_autohscroll; xywh 225 84 86 11;cc Invpos edit ws_border es_autohscroll; xywh 304 36 47 11;cc circ0 button;cn "Set_Circle"; xywh 224 101 38 10;cc label static;cn "P (X, Y)"; xywh 269 100 50 11;cc inPXY edit ws_border es_autohscroll; xywh 224 115 34 10;cc label static;cn "P (R)"; xywh 271 116 51 11;cc inPR edit ws_border es_autohscroll; xywh 224 132 34 11;cc PCircle button; xywh 275 133 34 11;cc QCircle button; xywh 242 6 34 11;cc Clear button; xywh 224 50 84 11;cc Stpos edit ws_border es_autohscroll; xywh 260 67 34 11;cc InV button; xywh 276 154 34 11;cc QStep button; xywh 225 153 34 11;cc StepON button; pas 6 6;pcenter; rem form end; ) run =: invergraph_run invergraph_run=: 3 : 0 wd INVERGRAPH NB. initialize form here x0 =: 500 y0 =: 500 NB. sz =: 0.5 NB. size sz =: 1 Box =: 0 draw_xy '' glshow '' wd 'pshow;' ) invergraph_close=: 3 : 0 wd'pclose' ) invergraph_cancel_button=: 3 : 0 invergraph_close'' ) invergraph_Clear_button=: 3 : 0 glclear '' x0 =: 500 y0 =: 500 sz =: 1 NB. size glshow '' ) NB. Graphics Utilities by TN ============================================= adj0 =: 3 : 0 NB. centered 1 adj0 y. : NB. 500 + 100 * x. * y. (x0, y0) + "(1) > cut2 100 * x. * y. NB. y-axis down NB. (500, 400) + "(1) > cut2 100 * x. * y. NB. y-axis down ) adj =: 3 : 0 NB. start left down 1 adj y. : NB. (500&+)@(100&*) 200 + 40 * x. * y. ) NB. cut2 i.10 NB. +---+---+---+---+---+ NB. |0 1|2 3|4 5|6 7|8 9| NB. +---+---+---+---+---+ cut2 =: 3 : 0 y =. ((-:#y.),2)$y. <"(1) y ) NB. eg. 30 rotate figure(x0, y0, x1, y1, .. ) around (0, 0) rot =: 3 : 0 : 'x y' =. y. t =. x. ((x*cosd t) - (y*sind t)), ((x*sind t) + (y*cosd t)) ) rotate =: 3 : 0 : ANG =. x. RXY =. cut2 , > y. RX =. {."(1) > ANG rot L:0 RXY RY =. {:"(1) > ANG rot L:0 RXY , |: RX ,: RY ) NB. eg. (1, 2) shift x, y shift =: 3 : 0 : 'Xs Ys' =. x. , (Xs, Ys) +"(1) > cut2 y. ) colorpolygon =: 3 : 0 : glrgb x. glbrush '' glpen 1 0 NB. glpolygon , sz adj0 y. glpolygon , sz adj0 y. ) colorpolylines =: 3 : 0 : glrgb x. glbrush '' glpen 1 0 gllines , sz adj0 y. ) draw_xy =: 3 : 0 glrgb 0 0 0 glpen 1 0 gllines 10 500 990 500 gllines 500 10 500 990 ) circle =: 3 : 0 'x y r' =. y. TH =. 15 * i. 25 NB. circle = 15 deg * 24 times XX =. x + r * cosd TH YY =. y + r * sind TH , XX ,. YY ) NB. Begin Inversion Geometry Process ====================================== invergraph_inxy_button=: 3 : 0 'X0 Y0' =: ". inxy ) invergraph_inr_button=: 3 : 0 R0 =: ". inr ) invergraph_circ0_button=: 3 : 0 CIRC =: circle X0,Y0, R0 (255 0 0) colorpolylines CIRC draw_xy '' glshow '' ) NB. Mouse Left => Accept Initial Position for First ============= NB. Display Mouse Position X, Y NB. Modified for Inversion 2019/8/4 NB. mouse left button => figure will move to clicked position NB. Mouse Left Button Input Point =============================== NB. Start with Left Button invergraph_invgraph_mbldown=: 3 : 0 d=. ". sysdata x=. (0{d) * 1000 % (2{d) y=. (1{d) * 1000 % (3{d) x0 =: (x - 500) % 100 y0 =: (y - 500) % 100 NB. wr 'Initial Position: (', (5j1": x0), ', ' , (5j1": y0), ')' wd 'set Stpos *', ' (', (5j2": x0), ', ' , (5j2": y0), ')' NB. wd 'set SQStpos *', (5j2": %: +/ *: x0, y0) Pos =. circle (5 + x0), (5 + y0), 0.05 (0 0 255) colorpolygon Pos glshow '' ) invergraph_Stpos_button=: 3 : 0 StPos =: ". Stpos ) NB. Inversion Button ================================================= NB. invergraph_Invert_button=: 3 : 0 NB. wr 'Invert' NB. ) invergraph_Invert_button=: 3 : 0 xx0 =: (*: R0) % x0 yy0 =: (*: R0) % y0 NB. wr'Inverted Position: (', (5j1": xx0), ', ' , (5j1": yy0), ')' wd 'set Inpos *', ' (', (5j2": xx0), ', ' , (5j2": yy0), ')' InPos =. circle (5 + xx0), (5 + yy0), 0.05 (0 255 0) colorpolygon InPos glshow '' ) NB. Inversion Mouse Right Button ================================================= NB. mouse right buton => figure size will be smaller invergraph_invgraph_mbrdown=: 3 : 0 NB. d=. ". sysdata NB. x=. (0{d) * 1000 % (2{d) NB. y=. (1{d) * 1000 % (3{d) NB. x0 =. (x - 500) % 50 NB. y0 =. (y - 500) % 50 xx0 =: (*: R0) % x0 yy0 =: (*: R0) % y0 NB. wr 'Initial Position: (', (5j2": x0), ', ' , (5j2": y0), ')' NB. wr 'Inversion Position: (', (5j2": xx0), ', ' , (5j2": yy0), ')' NB. wd 'set Inpos *', ' (', (5j2": xx0), ', ' , (5j2": yy0), ')' NB. wd 'set SQInpos *', (5j2": +/ *: xx0, yy0) NB. wd 'set InvCheck *', (5j2": ( */ (+/ *: x0, y0), (+/ *: xx0, yy0)) ) NB. invert ============================== if. y0 = 0 do. QQX =. invert x0 wd 'set Invpos *', ' (', (5j2": QQX), ', ' , (5j2": 0), ')' InPos =. circle (5 + QQX), (5 + 0), 0.05 (0 255 0) colorpolygon InPos glshow '' else. TT =. invertt x0, y0 'ttx tty' =. TT wd 'set Invpos *', (5j2": ttx, tty) NB. wd 'set SQInpos *', (5j2": %: +/ *: ttx, tty) check =: %: (%: +/ *: x0, y0) * (%: +/ *: ttx, tty) NB. wr (5j2": check) NB. wd 'set InvCheck *', (5j2": check) tPos =. circle (5 + ttx), (5 + tty), 0.05 (0 255 0) colorpolygon tPos glshow '' end. ) invert =: 3 : 0 x0 =. y. pp =. x0 - X0 th =. arccos ( pp % R0) R0 % (cos th) ) invertt =: 3 : 0 'sx sy' =. y. sx =. sx - X0 sy =. sy - Y0 len =. (*: R0) % (%: +/ *: sx, sy) salph =. arctan(sx % sy) tx =. len * cos salph ty =. len * sin salph tx, ty ) invergraph_InV_button=: 3 : 0 invergraph_invgraph_mbrdown '' ) NB. revised ============================================================== invergraph_Invpos_button=: 3 : 0 InPos =: ". Invpos ) NB. P and Q Process ===================================================== invergraph_inPXY_button=: 3 : 0 PXY =: ". inPXY ) invergraph_inPR_button=: 3 : 0 PR =: ". inPR ) invergraph_PCircle_button=: 3 : 0 NB. wr PXY, PR PCIRC =: circle PXY, PR NB. wr PCIRC (0 0 255) colorpolylines PCIRC draw_xy '' glshow '' ) invergraph_QCircle_button=: 3 : 0 NB. wr (25, 2)$PCIRC PN =: 26 PX =: {."(1) (PN, 2)$PCIRC PY =: {:"(1) (PN, 2)$PCIRC NB. wr ' PX PY QX QY' NB. wr ' --------------------------------------' i =. 0 while. i < PN do. PXI =. i{PX PYI =. i{PY 'QXI QYI' =. invertt (i{PX), (i{PY) NB. wr (2j0": i), (7j2": (i{PX), (i{PY), QXI, QYI) PXYI =. %: +/ *: PXI, PYI QXYI =. %: +/ *: QXI, QYI PQXYI =. PXYI * QXYI NB. wr (2j0": i), (7j2": (i{PX), (i{PY), QXI, QYI, (PQXYI) ) QCIRCI =. circle (QXI), (QYI), 0.05 NB. if. QSTON = 0 NB. do. (0 255 0) colorpolygon QCIRCI NB. else. NB. wr QSTON NB. end. i =. i + 1 end. glshow '' ) NB. Invert Step ==================================== invergraph_StepON_button=: 3 : 0 PN =: 26 PX =: {."(1) (PN, 2)$PCIRC PY =: {:"(1) (PN, 2)$PCIRC STi =: 0 ) invergraph_QStep_button=: 3 : 0 PXI =. STi{PX PYI =. STi{PY PCIRCI =. circle (PXI), (PYI), 0.05 (0 0 255) colorpolygon PCIRCI 'QXI QYI' =. invertt (PXI, PYI) PXYI =. %: +/ *: PXI, PYI QXYI =. %: +/ *: QXI, QYI PQXYI =. PXYI * QXYI QCIRCI =. circle (QXI), (QYI), 0.05 (0 255 0) colorpolygon QCIRCI STi =: STi + 1 glshow '' )