require 'numeric trig png plot' require '~temp/math/linear_math/vec_quaternion.ijs' NB. -------------------------------------------- NB. common utilities tap=: i.@! A. i. plot_view_sub=: 1 : 0 NB. 3D command NB. NB is default NB. usage: ". plot_view_sub pd 'boxed 0' pd 'viewup 0 0 1' NB. 0 0 1 pd 'viewcenter 0 0 1' NB. 0 0 0 pd 'viewsize 1 1 1' NB. 1 1 0.5 pd 'viewpoint 1.6 _2.4 1.5' NB. 1.6 _2.4 1.5 ) NB. --------------------- plot_Q=: 3 : 0 NB. u 1 4 4 _4 if. 4= # y do. tmp=. }. y else. tmp=. y end. a0=.{0 0 0 ,. tmp pd 'reset' ". plot_view_sub pd 'boxed 1' pd 'pensize 2' pd a0 pd 'show' ) NB. boxed 0 ----> non Box NB. -------------------------------- mk_vec_3d=: 3 : '{ 0 0 0,. y' NB. usage: u 0 2 0 NB. --------------------------- NB. circle by parameter circ=: 3 : ' r. 2p1 * (i.360)%360' NB. usage: circ '' add_zero=: 3 : ' 0 , L:0 y , (L:0) 0' NB. usage u y compose_qp_circ=: 4 : 0 NB. for draw parametric circle NB. usage: a2=. (1r4p1;1 1 0)compose_qp_circ a q0=. mk_q_rad x p0=. add_zero y q0 ,. L:0 p0 ) NB. ----------------------------- plot_2qp=: 3 : 0 NB. usage: plot_2qp 1r2p1;1 1 1 a1=. { +. circ '' a2=. y compose_qp_circ a1 a2=. rotateQ_rotmat L:0 a2 pd 'reset' ". plot_view_sub pd 'pensize 2' pd {|: ( > a1),.0 pd {|: }."1 > a2 NB. rotateQ_mat L:0 y pd 'show' ) NB. ----------------------- rotateQ_rotmat=: 3 : 0 'q0 p0'=.{|: y mat=. mk_Q_rotmat q0 p1=. 1 |. p0 _1 |. mat +/ . * p1 ) mk_Q_rotmat=: 3 : 0 NB. y is q0 NB. mat is i ,j, k, omega b0=.(2 3;1 3;1 2){ L:0 *: y b01=. ; -.@ +:@ +/ L:0 b0 index0=. { ~. /:~("1) 2{."1 tap 4 a0=.index0 { L:0 y a01=. */ L:0 a0 a02=. _2<\;(3 2 4 1 5 0){a01 a03=.a02, 1 _1 * L:0 a02 a04=. +: ; +/ L:0 a03 tmp0=. b01,a04 tmp1=.3 3 $ 0 6 4 3 1 8 7 5 2 { tmp0 (tmp1,0 0 0),. 0 0 0 1 ) test_param3d_6 =: 3 : 0 NB. spare t=. steps _1p1 1p1 100 s=. steps _2p1 2p1 100 a0=. (cos s) */ cos t a1=. (sin s) */ cos t a2=. ($ a1) $ sin t ax=. a0 ; a1 ; a2 pd 'reset' pd ' color blue' pd 'viewpoint 1 _2 1' pd 'type wire' pd ax pd 'show' ) plot_param_3d=: 3 : 0 tmp=. y pd 'reset' pd 'type wire' pd ' color blue' ". plot_view_sub pd tmp pd 'show' ) mk_param_phase=: 3 : 0 NB. usage: mk_param_phase '' // OK NB. fixed example s=. steps _1p1 1p1 90 t=. steps _1r2p1 1r2p1 30 a0=. (cos s) */ cos t a1=. (sin s) */ cos t a2=. ($ a1) $ sin t clean ax=. a0 ; a1 ; a2 ) mk_param_phase2=: 3 : 0 NB. for change parameter NB. usage: mk_param_phase '' // OK s=. steps _1p1 1p1 90 t=. steps _1r2p1 1r2p1 30 a0=. (cos s) */ cos t a1=. (sin s) */ cos t a2=. ($ a1) $ sin t clean ax=. a0 ; a1 ; a2 ) NB. quaternion rotate lineup_p=: 3 : '{ |:> , L:0 y' NB. usage: u mk_param_phase '' NB. lineup_p=:lineup_p0@mk_param_phase compose_qp_phase=: 3 : 0 NB. u (1r2p1; 1 1 1 ) px=. 0 , L:0 lineup_p@mk_param_phase2 '' qx=. mk_q_rad y qx ,. L:0 px ) calc_qp_phase=: 3 : 0 tmp=. compose_qp_phase y rotateQ_rotmat L:0 tmp )