Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct reper {
- triple o,i,j,k;
- guide3 oi,oj,ok;
- string olabel,ilabel,jlabel,klabel,labelsize;
- transform3 trans;
- void update_axis() {
- this.oi = this.o -- this.o+this.i;
- this.oj = this.o -- this.o+this.j;
- this.ok = this.o -- this.o+this.k;
- }
- void operator init(triple o=(0,0,0),triple i=(1,0,0),triple k=(0,-1,0),
- triple j=(0,0,1),string ilabel="\vec{i}",
- string jlabel="\vec{j}",string klabel="\vec{k}",
- string olabel="o",string labelsize="\footnotesize"){
- this.o = o; this.i = i; this.j = j; this.k = k;
- this.update_axis();
- this.olabel = olabel; this.ilabel = ilabel;
- this.jlabel = jlabel; this.klabel = klabel;
- this.labelsize = labelsize;
- trans = identity4;
- }
- void shift(triple dxyz) {
- this.o += dxyz;
- trans *= three.shift(dxyz);
- this.update_axis();
- }
- void rotate(real alpha,triple u) {
- this.i = three.rotate(alpha,u)*this.i;
- this.j = three.rotate(alpha,u)*this.j;
- this.k = three.rotate(alpha,u)*this.k;
- trans *= three.rotate(alpha,u);
- this.update_axis();
- }
- void draw(triple view_point) {
- draw(this.oi,red,Arrow3);
- draw(this.oj,red,Arrow3);
- draw(this.ok,red,Arrow3);
- real dij = dot(view_point-this.o,cross(this.i,this.j));
- triple shift_o = unit(this.i+this.j);
- if (dij<0) { shift_o = - shift_o; }
- label(this.labelsize+" $"+this.olabel+"$",this.o,shift_o,blue);
- triple shift_i = cross(this.i,view_point-this.o);
- shift_i = unit(shift_i);
- label(this.labelsize+" $"+this.ilabel+"$",this.o+this.i/2,shift_i,blue);
- triple shift_j = cross(this.j,view_point-this.o);
- shift_j = unit(shift_j);
- label(this.labelsize+" $"+this.jlabel+"$",this.o+this.j/2,shift_j,blue);
- triple shift_k = cross(this.k,view_point-this.o);
- shift_k = unit(shift_k);
- label(this.labelsize+" $"+this.klabel+"$",this.o+this.k/2,shift_k,blue);
- }
- triple fromModel(triple pt) {
- real[] pp = {pt.x, pt.y, pt.z, 1};
- pp = this.trans*pp;
- return (pp[0], pp[1], pp[2]);
- }
- triple toModel(triple pt) {
- real[] pp = {pt.x, pt.y, pt.z, 1};
- pp = inverse(this.trans)*pp;
- return (pp[0], pp[1], pp[2]);
- }
- }//Koniec definicji klasy reper
- settings.outformat="pdf";
- settings . prc= false ;
- defaultfilename = "reper-2" ;
- size3 ( 16cm , 16cm , keepAspect=true) ;
- size ( 16cm , 16cm , keepAspect=true) ;
- texpreamble("\def\vec#1{\overrightarrow{#1}}");
- reper r = reper ( labelsize="\tiny" ) ;
- write ( 'o=' , r.o ) ; write ( 'i=' , r.i ) ;
- write ( 'j=' , r.j ) ; write ( 'k=' , r.k ) ;
- triple view_point = (30 , -30 ,30);
- currentprojection = perspective ( view_point ) ;
- r.draw ( view_point ) ;
- r.shift ((2 ,0 ,0));
- r.draw ( view_point ) ;
- r.shift ((0 ,2 ,0));
- r.rotate (60 , r.k ) ;
- r.draw ( view_point ) ;
- triple p1 = (1,0,0);
- dot (p1, blue);
- triple p2 = r.fromModel(p1);
- dot (p2, blue);
- triple p3 = r.toModel(p2);
- write('p1=', p1);
- write('p2=', p2);
- write('p3=', p3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement