一個圓周計算的問題 |
尚未結案
|
harisan3
一般會員 發表:6 回覆:11 積分:3 註冊:2004-12-10 發送簡訊給我 |
void MakeEllipticalOutline(OUTLINE *outline, int xrad, int yrad) { short *ptr; float *ptrn; int xradsq = xrad * xrad; int yradsq = yrad * yrad; double ratio = ((double) xradsq) / ((double) yradsq); int xradbkpt = (int) (xradsq / sqrt((double) xradsq yradsq)); int yradbkpt = (int) (yradsq / sqrt((double) xradsq yradsq)); int x, y; // x & y are in image coordinates int curx, cury; // count # of iterations in loops below outline->perim_length = 4 * xradbkpt 4 * yradbkpt 4; outline->perim = (short *) malloc(2 * (outline->perim_length) * sizeof(short)); outline->normals = (float *) malloc(2 * (outline->perim_length) * sizeof(float)); ptr = outline->perim; ptrn = outline->normals; *(ptr) = curx = 0; // perimeter starts at top and proceeds clockwise *(ptr) = cury = - yrad; *ptrn = 0.0f; *ptrn = -1.0f; // from 0 to 45 degrees, measured cw from top for (x = 1; x <= xradbkpt ; x ) { y = (int) (-yrad * sqrt(1 - ((double) x / xrad)*((double) x / xrad))); *(ptr) = x - curx; *(ptr) = y - cury; *ptrn = (float) ( x / sqrt(x*x ratio*y*y)); *ptrn = (float) ((ratio*y) / sqrt(x*x ratio*y*y)); curx = x; cury = y; } // from 45 to 135 degrees (including right axis) for (y = - yradbkpt ; y <= yradbkpt ; y ) { x = (int) (xrad * sqrt(1 - ((double) y / yrad)*((double) y / yrad))); *(ptr) = x - curx; *(ptr) = y - cury; *ptrn = (float) ( x / sqrt(x*x ratio*y*y)); *ptrn = (float) ((ratio*y) / sqrt(x*x ratio*y*y)); curx = x; cury = y; } // from 135 to 225 degrees (including down axis) for (x = xradbkpt ; x >= - xradbkpt ; x--) { y = (int) (yrad * sqrt(1 - ((double) x / xrad)*((double) x / xrad))); *(ptr) = x - curx; *(ptr) = y - cury; *ptrn = (float) ( x / sqrt(x*x ratio*y*y)); *ptrn = (float) ((ratio*y) / sqrt(x*x ratio*y*y)); curx = x; cury = y; } // from 225 to 315 degrees (including left axis) for (y = yradbkpt ; y >= - yradbkpt ; y--) { x = (int) (-xrad * sqrt(1 - ((double) y / yrad)*((double) y / yrad))); *(ptr) = x - curx; *(ptr) = y - cury; *ptrn = (float) ( x / sqrt(x*x ratio*y*y)); *ptrn = (float) ((ratio*y) / sqrt(x*x ratio*y*y)); curx = x; cury = y; } // from 315 to 360 degrees for (x = - xradbkpt ; x < 0 ; x ) { y = (int) (-yrad * sqrt(1 - ((double) x / xrad)*((double) x / xrad))); *(ptr) = x - curx; *(ptr) = y - cury; *ptrn = (float) ( x / sqrt(x*x ratio*y*y)); *ptrn = (float) ((ratio*y) / sqrt(x*x ratio*y*y)); curx = x; cury = y; } outline->halfsize_x = xrad; outline->halfsize_y = yrad; outline->area = MakeMask(outline); }請問個數學問題,為什麼圓周上面的點的算法會變成下面的寫法? // from 0 to 45 degrees, measured cw from top for (x = 1; x <= xradbkpt ; x ) { y = (int) (-yrad * sqrt(1 - ((double) x / xrad)*((double) x / xrad)));我帶數學公式還是無法理解,請各位數學比較好的幫幫我解釋一下,感恩喔. |
spruce
一般會員 發表:3 回覆:11 積分:2 註冊:2005-11-05 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |