void adddirtoscene(Scene *s,DirRec *dr,V3d pos,V3d up) { // printf("Adding directory %s\n",dr->fname); s->add(new Cylinder(pos+0.0*up,pos+1.0*up,0.05*up.mod())); pos=pos+up; // s->add(new TextRend(dr->fname,10,pos,0.3)); OrderedList<FileRec> ol; for (int i=1; i<=dr->fs.len; i++) { FileRec *r=dr->fs.num(i); ol.add(r,ordering(r)); } V3d x=V3d::normcross(up,V3d::k)*up.mod()*0.8; // Actually, want y=closest to real z V3d y=V3d::normcross(up,x)*up.mod()*0.8; for (int i=1; i<=ol.len; i++) { FileRec *r=ol.p2num(i); // printf(" %s\n",r->fname); float ang=((i%2)==0?1:-1)*(pi*(float)(i-1)/(float)(ol.len-1)); V3d d=up+x*mysin(ang)+y*mycos(ang); // Bad, should do rotation instead. if (Seq(r->type(),"file")) { //s->add(new Cylinder(pos+0.0*d,pos+0.2*d,0.05*up.mod())); s->add(new Sphere(pos+0.1*d,0.02*up.mod())); // s->add(new TextRend(r->fname,10,pos+d,0.1)); } else { DirRec *dr2=(DirRec *)r; adddirtoscene(s,dr2,pos,d.norm()*up.mod()*0.9); } } }
float smoothvalat(int x,int y) { V2d tofar=V2d(x,y)-pos; float d=V2d::dot(V2d::angle(ang),tofar); return mysin(d/rad*2*pi)*gaussian(tofar.mod()/200); // return mysin(d/rad*2*pi)/d*100.0; // return gaussian(d/100.0)*mysin(d/rad*2*pi)/d*100.0; }
// a = sin(theta)/cos(theta) void draw_line(U16* buf, S16 r, U16 theta,d_YUV* d_pixel_value){ S16 x, y; U16 blue = 0x1f; float Usum=0,Vsum=0; if(theta == 90){ return; } for(x = 0; x < 180; x++){ y = (S16)(-(mysin(theta)/mycos(theta))*x + r/mycos(theta)); if (x%20 ==0) { //printf("y : %d\n", y); } if(y >= 0 && y < 120) { red = RED_VALUE_IN565(buf[180*y + x]); blue = BLUE_VALUE_IN565(buf[180*y + x]); green = GREEN_VALUE_IN565(buf[180*y + x]); Y = 0.299*red + 0.293*green + 0.114*blue; U = 0.492*(0.886*blue - 0.299*red - 0.293*green); V = 0.877*(0.701*red - 0.293*green - 0.114*blue); buf[180*y + x] = blue; } Usum += U; Vsum += V; } Usum = Usum/180; Vsum = Vsum/180; d_pixel_value->u_value = Usum; d_pixel_value->v_value = Vsum; //printf("----- r : %d, theta : %d\n", r, theta); }
int draw_rotate_value(int cdx, int cdy, int ctx, int cty, float zoom, unsigned int angle, DrawRaw_value* draw_value) { float sinval, cosval; int InitDX, InitDY; int EndX, EndY; int InitSX, InitSY; int dxSx, dxSy; int dySx, dySy; int dx,dy; int x, y; int cosa; int sina; int rhzoom; long tx,ty; x = y = 0; dx = SCREEN_WIDTH; // screen width (320) dy = SCREEN_HEIGHT; // screen height (480) sinval = mysin(angle); cosval = mycos(angle); tx = (-cdx/zoom) * cosval + (-cdy/zoom) * sinval; ty = (cdx/zoom) * sinval + (-cdy/zoom) * cosval; if( zoom<=0 ) rhzoom = 0; else rhzoom = (int)((float)(1<<9)/zoom); cosa = (S32)(rhzoom * cosval); sina = (S32)(rhzoom * sinval); if( dx <= 0 || dy <= 0 ) return -1; InitDX = x; InitDY = y; EndX = x+dx-1; EndY = y+dy-1; InitSX = (x+tx+ctx)*512; dxSx = cosa; dxSy = -sina; InitSY = (y+ty+cty)*512; dySx = sina; dySy = cosa; draw_value->InitDX=InitDX; draw_value->InitDY=InitDY; draw_value->EndX=EndX; draw_value->EndY=EndY; draw_value->InitSX=InitSX; draw_value->InitSY=InitSY; draw_value->dxSx=dxSx; draw_value->dxSy=dxSy; draw_value->dySx=dySx; draw_value->dySy=dySy; return 0; }
double mysin(double n, double x) { int k; double fl, rem, val, flx = fl*x;; if ( n > 2 ) { k = floor(log2(n)); fl = pow(2,k); rem = n - fl; flx = fl*x; val = cos(flx)*mysin(rem,x) + sin(flx)*mycos(rem,x); } else val = sin(n*x); return(val); }
StatusCode CpuHungryAlg::execute() { m_nevent++; double result = 0; if (name() == "Alg1") { result = mysin(); }else if (name() == "Alg2") { result = mycos(); }else { result = mytan(); } // This part is pointless, but prevent a warning about a // set, but unused, variable (result). if ( msgLevel(MSG::DEBUG) ) debug() << "Result = " << result << endmsg; return StatusCode::SUCCESS; }
double asymbesselj(double nu, double n, double x) { double pp, fournu2 = 4.*nu*nu, cosx, sinx, cosp, sinp, cosW, sinW, man, wife, a, sgn, tmp, vals; int j, MM = 30; // avg frequency. pp = (.5*nu+.25)*PI; // coefficients a = 1.; sgn = 1.0; man = 1.; wife = 0.; for (j = 1; j <= MM/2; j+=2) { tmp = (2.*j-1.); a *= (fournu2-tmp*tmp)/(8.*j)/n/x; wife += a; sgn = -sgn; tmp = (2.*j+1.); a *= sgn*(fournu2-tmp*tmp)/(8.*(j+1))/n/x; man += a; sgn = -sgn; } // factor out the average frequency cosx = mycos(n,x); sinx = mysin(n,x); cosp = cos(pp); sinp = sin(pp); cosW = cosx*cosp + sinx*sinp; sinW = sinx*cosp - cosx*sinp; // besselj is the marriage of two parts. man *= cosW; wife *= sinW; // combine vals = sqrt(2./PI)*(1./sqrt(n))*(1./sqrt(x))*(man - wife); return(vals); }
void ClarkePark() { SCP.cosangle=( int16_t ) mycos( SCP.angle)/32; // into lower 10 fractional bits SCP.sinangle= ( int16_t ) mysin( SCP.angle )/32; SCP.Ialpha=SCP.Ia; SCP.Ibeta = fix6_10_mul(SCP.Ia, (int16_t ) ONEDIVSQ3 )+fix6_10_mul(SCP.Ib , (int16_t) ONEDIVSQ3 * 2 ) ; SCP.Id= fix6_10_mul(SCP.Ialpha , SCP.cosangle ) +fix6_10_mul(SCP.Ibeta , SCP.sinangle ); SCP.Iq= - fix6_10_mul(SCP.Ialpha , SCP.sinangle ) + fix6_10_mul(SCP.Ibeta , SCP.cosangle ); //SCP.Id =-SCP.Id; // ## Achtung //SCP.Iq =-SCP.Iq; }
static int compute_pedal(struct state *st, XPoint *points, int maxpoints) /* * Description: * * Basically, it's combination spirograph and string art. * Instead of doing lines, we just use a complex polygon, * and use an even/odd rule for filling in between. * * The spirograph, in mathematical terms is a polar * plot of the form r = sin (theta * c); * The string art of this is that we evaluate that * function only on certain multiples of theta. That is * we let theta advance in some random increment. And then * we draw a straight line between those two adjacent points. * * Eventually, the lines will start repeating themselves * if we've evaluated theta on some rational portion of the * whole. * * The number of lines generated is limited to the * ratio of the increment we put on theta to the whole. * If we say that there are 360 degrees in a circle, then we * will never have more than 360 lines. * * Return: * * The number of points. * */ { int a, b, d; /* These describe a unique pedal */ double r; int theta = 0; XPoint *pp = st->points; int count; int numpoints; /* Just to make sure that this division is not done inside the loop */ int h_width = st->sizex / 2, h_height = st->sizey / 2 ; for (;;) { d = rand_range (MINLINES, st->maxlines); a = rand_range (1, d); b = rand_range (1, d); numpoints = numlines(a, b, d); if (numpoints > MINLINES) break; } /* it might be nice to try to move as much sin and cos computing * (or at least the argument computing) out of the loop. */ for (count = numpoints; count-- ; ) { r = mysin (theta * a, d); /* Convert from polar to cartesian coordinates */ /* We could round the results, but coercing seems just fine */ pp->x = mysin (theta, d) * r * h_width + h_width; pp->y = mycos (theta, d) * r * h_height + h_height; /* Advance index into array */ pp++; /* Advance theta */ theta += b; theta %= d; } return(numpoints); }
virtual float smoothvalat(int x,int y) { float d=V2d::dist(V2d(x,y),pos); // return gaussian(d/200.0)*mysin(d/rad*2*pi); return log(d/200.0)*mysin(d/rad*2*pi)*gaussian(d/100); }
/*Hough space 180x120 x-y space to --> angle 180 | OOOOOOOOOOOOOOOOOOOOOO | OOOOOOOOOOOOOOOOOOOOOO | OOOOOOOOOOOOOOOOOOOOOO | OOOOOOOOOOOOOOOOOOOOOO --------(diag)--------(diag*2)-----> */ void hough_lines(U16* buf, U16 threshold_value, double resolution, U16 num_line, S16* p_radius, U16* p_theta,d_YUV* d_pixel_value){ int width = 180, height = 120, r, c, i, j, k; U16 diagH = (U16)(sqrt((double)(180*180 + 120*120))); U16 diag = diagH*2; U16 res_step = (U16)(180/resolution); // In resolution 1, each step has 1 degree. U16 num_trans = diag*res_step; U16 hough_space[num_trans]; U16 theta; memset(hough_space, 0, num_trans*sizeof(U16)); for(r = 5; r < height - 5; r++){ for(c = 5; c < width - 5; c++){ int distance; // At each edge pixels if(BLUE_VALUE_IN565(buf[180*r + c]) > threshold_value){ //printf("selected pixel : y=%d, x=%d\n", r, c); for(theta = 0; theta < 180; theta += (U16)resolution){ distance = (int)(c*mysin(theta) + r*mycos(theta) + diagH + 0.5); hough_space[distance*res_step + (U16)(theta/resolution)]++; } } } } int highest_voted_pixel[6] = {0, 0, 0, 0, 0, 0}; int highest_voted_pixel_index[6] = {0, 0, 0, 0, 0, 0}; for(i = 0; i < num_trans; i++){ if(hough_space[i] >= highest_voted_pixel[0]){ // push highest_voted_pixel, index array for(j = 5; (j >= 0) && (hough_space[i] >= highest_voted_pixel[j]); j--){ for(k = 1; k < j + 1; k++){ highest_voted_pixel[k-1] = highest_voted_pixel[k]; highest_voted_pixel_index[k-1] = highest_voted_pixel_index[k]; } highest_voted_pixel[j] = hough_space[i]; highest_voted_pixel_index[j] = i; break; } } } for(i = 0; i < 6; i++){ p_radius[i] = (S16)(highest_voted_pixel_index[i]/res_step); p_theta[i] = (highest_voted_pixel_index[i] - p_radius[i]*res_step)*resolution; p_radius[i] -= diagH; //printf("line detected. voted : %d, index : %d, r : %d / theta : %d\n", highest_voted_pixel[i], highest_voted_pixel_index[i], p_radius[i], p_theta[i]); //printf("\n"); } float d_Usum=0,d_Vsum=0; for(i = 0; i < 6; i++){ draw_line(buf, p_radius[i], p_theta[i],d_pixel_value); printf("each direct%d U_value : %0.3f, V_value : %0.3f\n",i+1,d_pixel_value->u_value,d_pixel_value->v_value); } /*for(line_count = 0; line_count < num_line; line_count++){ printf("line no. %d p_r : %d / p_t : %d\n", line_count, p_radius[line_count], p_theta[line_count]); }*/ }
static float mycos(U32 angle) { return mysin(angle + 90); }
V3d contribution(float thru) { return a*line*mysin(((float)f)*(thru*2.0*pi-o)); // return V3d::random(); }
double mycos(double x) { //APP_LOG(APP_LOG_LEVEL_DEBUG, "in cos called with %d", (int)(x * 1000)); return mysin(M_PI / 2 - x); }
double bar(double x) { return mysin(x); }