/********************************************************************* * INVERSION OF A 2D CURVE * * ------------------------------------------------------------------ * * Explanations: * * The inversion is defined by a point o, as origin, and a real number* * p <> 0. Any point a is transformed into a point a', such as: * * * * _____.____________.___________.__________ * * o a a' * * * * oa x oa' = p * * * * This small program calculates and draws the inverse of a polar * * curve, defined as Rho = F(t). * * ------------------------------------------------------------------ * * Sample Run: * * The example is defined as: Rho = 2 + cos(7*t) * * Inversion Power = 5 * * ------------------------------------------------------------------ * * From "Graphisme dans le plan et dans l'espace avec Turbo Pascal 4.0* * de R. Dony - MASSON 1990", page 223". * * * * Visual C++ in API style By J-P Moreau, Paris. * *********************************************************************/ #include #include #include #include HDC hdc; RECT rect; //Functions of module Gr2D.cpp void Fenetre(double,double,double,double); void Cloture(int,int,int,int); void Bordure(); void Axes(); void Gradue(double,double); void Grille(double,double); void MoveXY(double,double); void LineXY(double,double); void Cercle(double,double,double,int); //"home made" graphic commands for hdc environment used by above functions void DrawPixel(int ix,int iy) { //sorry, no other available command found Rectangle(hdc,rect.left+ix,rect.top+iy, rect.left+ix+2,rect.top+iy+1); } void Swap(int *i1,int *i2) { int it; it=*i1; *i1=*i2; *i2=it; } void DrawLine(int ix1,int iy1,int ix2,int iy2) { int i,il,ix,iy; float dx,dy; if (ix2 0) Cercle(0,0,sqrt(puiss),1); t=1e-20; x=Rho(t); y=0; MoveXY(x,y); while (t<=lim) { t=t+pas; x=Rho(t)*cos(t); y=Rho(t)*sin(t); LineXY(x,y); } } //draw curve after geometrical inversion void DrawInvertedCurve() { REAL_AR t,r1,r2,x,y; t=1e-20; r1=Rho(t); if (r1==0) r2=puiss/1e-37; else r2=puiss/r1; x=r2*cos(t); y=r2*sin(t); MoveXY(x,y); while (t<=lim) { t=t+pas; r1=Rho(t); r2=puiss/r1; x=r2*cos(t); y=r2*sin(t); LineXY(x,y); } } // main function void Exec_Inversion() { char s[20]; extern MaxX, MaxY; MaxX=(rect.right-rect.left); MaxY=(rect.bottom-rect.top); Data(); DrawInitialCurve(); DrawInvertedCurve(); OutText(60,40,"GEOMETRICAL INVERSION"); sprintf(s,"Power = %6.2f", puiss); OutText(MaxX-175,MaxY-110, s); } //end specific section //Handle window Paint and Destroy messages long FAR PASCAL /*_export*/ WndProc(HWND hwnd, UINT message, UINT wParam, LONG lParam) { HPEN hpen, hpenOld; PAINTSTRUCT ps; switch (message) { case WM_PAINT: hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rect); hpen = CreatePen(PS_SOLID, 1, RGB(0, 0, 255)); hpenOld = SelectObject(hdc,hpen); Exec_Inversion(); SelectObject(hdc,hpenOld); DeleteObject(hpen); EndPaint(hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); } // main program int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow) { static char szAppName[] = "Apollo"; HWND hwnd; MSG msg; WNDCLASS wndclass; if (!hPrevInstance) { wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; RegisterClass(&wndclass); } hwnd = CreateWindow(szAppName, // window class name " CIRCLES OF APOLLONIUS", // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL); // creation parameters ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } //end of file apollo.cpp