/* * utils.c * * Utility stuff * * (c) 2006-2009 Thomas White * * pattern_sim - Simulate diffraction patterns from small crystals * */ #include #include #include "utils.h" /* Return the MOST POSITIVE of two numbers */ unsigned int biggest(signed int a, signed int b) { if ( a>b ) { return a; } return b; } /* Return the LEAST POSITIVE of two numbers */ unsigned int smallest(signed int a, signed int b) { if ( a 0 ) return +1; return 0; } void mapping_rotate(double x, double y, double z, double *ddx, double *ddy, double *ddz, double omega, double tilt) { double nx, ny, nz; double x_temp, y_temp, z_temp; /* First: rotate image clockwise until tilt axis is aligned * horizontally. */ nx = x*cos(omega) + y*sin(omega); ny = -x*sin(omega) + y*cos(omega); nz = z; /* Now, tilt about the x-axis ANTICLOCKWISE around +x, i.e. the * "wrong" way. This is because the crystal is rotated in the * experiment, not the Ewald sphere. */ x_temp = nx; y_temp = ny; z_temp = nz; nx = x_temp; ny = cos(tilt)*y_temp + sin(tilt)*z_temp; nz = -sin(tilt)*y_temp + cos(tilt)*z_temp; /* Finally, reverse the omega rotation to restore the location of the * image in 3D space */ x_temp = nx; y_temp = ny; z_temp = nz; nx = x_temp*cos(-omega) + y_temp*sin(-omega); ny = -x_temp*sin(-omega) + y_temp*cos(-omega); nz = z_temp; *ddx = nx; *ddy = ny; *ddz = nz; } void progress_bar(int val, int total) { double frac; int n, i; char s[1024]; frac = (double)val/total; n = frac*80; for ( i=0; i