~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/math/transform/transform2.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)Transforms
  2  * @(#)Transform2 is {int type; struct mat2 R; struct vec2 t;}
  3 **/
  4 
  5 #include <stdio.h>
  6 #include <math.h>
  7 #include <tina/sys.h>
  8 #include <tina/sysfuncs.h>
  9 #include <tina/math.h>
 10 #include <tina/mathfuncs.h>
 11 
 12 void   *trans2_alloc(void)
 13 {
 14     Transform2 *transf = ts_ralloc(Transform2);
 15 
 16     transf->R = mat2_unit();
 17     transf->t = vec2_zero();
 18     return ((void *) transf);
 19 }
 20 
 21 void    trans2_free(void *transf)
 22 {
 23     rfree((void *) transf);
 24 }
 25 
 26 /**
 27 2D rotation through theta about point p
 28 
 29 (leaves p unchanged)
 30 **/
 31 
 32 Transform2 trans2_rot_about(double theta, Vec2 p)
 33 {
 34     Transform2 transf = {Transform2_id};
 35 
 36     transf.R = rot2(theta);
 37     transf.t = vec2_diff(p, mat2_vprod(transf.R, p));
 38     return (transf);
 39 }
 40 
 41 Transform2 trans2_prod(Transform2 transf2, Transform2 transf1)
 42 {
 43     Transform2 prod = {Transform2_id};
 44 
 45     prod.R = mat2_prod(transf2.R, transf1.R);
 46     prod.t = vec2_sum(transf2.t, mat2_vprod(transf2.R, transf1.t));
 47     return (prod);
 48 }
 49 
 50 Transform2 trans2_inverse(Transform2 transf)
 51 {
 52     Transform2 inv = {Transform2_id};
 53 
 54     inv.R = mat2_transpose(transf.R);
 55     inv.t = mat2_vprod(inv.R, vec2_minus(transf.t));
 56     return (inv);
 57 }
 58 
 59 Vec2    trans2_pos(Transform2 transf, Vec2 v)
 60 {
 61     return (vec2_sum(mat2_vprod(transf.R, v), transf.t));
 62 }
 63 
 64 Vec2    trans2_vec(Transform2 transf, Vec2 v)
 65 {
 66     return (mat2_vprod(transf.R, v));
 67 }
 68 
 69 void    trans2_print(FILE * fp, Transform2 trans)
 70 {
 71     mat2_print(fp, trans.R);
 72     vec2_print(fp, trans.t);
 73 }
 74 
 75 void    trans2_format(Transform2 trans)
 76 {
 77     mat2_format(trans.R);
 78     format("\n");
 79     vec2_format(trans.t);
 80 }
 81 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.