💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
一、 1、参数: arc1 = (-3.0 / 16.0)*Pild; int x1 = 290; int y1 = 410; line01light02(hdc, arc1, 19, x1,y1); //参数说明: hdc绘图板,入射角arc1= 7/16PI, x1=300,y1=410为入射光线初始坐标 ![](https://box.kancloud.cn/9ca60154e5a90e7c38c06e46602db9ae_824x757.png) 核心代码: ``` void line01light02(HDC hdc, double arc1, unsigned long lineLen, double X01, double Y01) { // cou02t.open("f:/Cout181206cou02t_1202.txt"); double arc1arg02 = regularAngle(arc1); double X001 = X01; double Y001 = Y01; double X002 = X001; double Y002 = Y001; line2normal(hdc, arc1, X001, Y001, RGB(0, 200, 200), 10); cout << "[arc1arg01:" << arc1 << "]-"; cout << "[arc1arg02:" << arc1 << "]; "; unsigned long itime = 0; double old1X001 = X001; double old1Y001 = Y001; double mid01X01 = X001; double mid01Y01 = Y001; double arc01normal01origin001; double arc1normal01; double fanshe01Arc01; double reflecteAng01; double Xorigin01; double Yorigin01; // //循环光走(光线前进-简称光进)并反射等 //do { // lable110start: if (lineLen < 1) { return; } lable120: itime = 1; cou02t << "[itime:" << itime << "]_"; lable220: //开始算 反射角,并 (继续)光进 Xorigin01 = cos(arc1arg02)*(double)itime; Yorigin01 = sin(arc1arg02)*(double)itime; lable230: X001 = Xorigin01 + old1X001; Y001 = Yorigin01 + old1Y001; setpixe02l(hdc, X001, Y001, RGB(255, 25, 0));// , 255, 0));//绘图封装,封装都是有目的 的;没有目的 的“瞎封装”…会从我的小组被开除--Terry. lable510: //判断并(光线)步进: //if先判断是否在月亮形状里: (isInC2littlecircle && !isInC1BigCircle) if (isInMoon(X001, Y001)) {//if110 itime = 1; lineLen--; old1X001 = X001; old1Y001 = Y001; itime++; goto lable220; }//if110 //与小圆的上弧相交,else if下面判断:是否出了月亮,即出了小圆,(当然)也出了大圆 else if ( isInMoon(old1X001,old1Y001) && (1!=isInC2littlecircle(X001,Y001) && 1!=isInC1BigCircle(X001,Y001) ) ) { double arc01normal01origin01 = atan( (400-X001)/(Y001-400) ); arc1normal01 = Pild / 2.0 + arc01normal01origin01; line2normal(hdc, arc1normal01, old1X001, old1Y001, RGB(0, 100, 0), 5); //暗绿色法线 fanshe01Arc01 = arc1arg02 - 2 * arc1normal01; reflecteAng01=Pild - fanshe01Arc01; line2normal(hdc, reflecteAng01, old1X001, old1Y001, RGB(0, 255, 0), 6);//亮绿色反射线 arc1arg02 = reflecteAng01; cou02t << "[01-arc1normal01:" << arc1normal01 << "]"; // system("pause"); goto lable220; }else if ( isInMoon(old1X001,old1Y001) && (1==isInC2littlecircle(X001,Y001) && 1==isInC1BigCircle(X001,Y001) ) ) { cou02t << "Hell01!" << endl; //if110elseif120 //elseif下面判断:是否出了月亮,既然在小圆内,(但)仍然在大圆内(两圆相交处 //先规格、规范化入射角: double arc1ang03=arc1arg02; // arc1ang03= regularAngle(arc1arg02); while (arc1ang03 > Pild) { arc1ang03 =arc1ang03- 2 * Pild; } while (arc1ang03 < -Pild) { arc1ang03 = arc1ang03 + 2*Pild; } //arc01normal01origin001 = atan((-400 +X001 / (Y001 - 0) ) ); arc01normal01origin001 = asin((-X001 + 400) / 400); arc1normal01 = Pild/2.0+ arc01normal01origin001;//(/*Pild / 2.0*/ - arc01normal01origin001); // line2normal(hdc, arc1normal01, old1X001, old1Y001, RGB(0, 200,0), 15); //暗Green法线 line2normal(hdc, Pild+arc1normal01, old1X001, old1Y001, RGB(0, 200, 0), 395); //暗Green法线 fanshe01Arc01 = Pild+arc1ang03 - 2 * arc1normal01; reflecteAng01 = -fanshe01Arc01; cou02t << "Hello!" << endl; cou02t << endl << "[入射角arc1arg02:" << arc1arg02 << "(角度:" << arc1arg02 * 180.0 / Pild << "]_"; cou02t << endl << "[入射角规范化arc1ang03:" << arc1ang03 << "(角度:" << arc1ang03 * 180.0 / Pild << "]_"; cou02t << endl<<"[法线arc01normal01origin001" << arc01normal01origin001 << "(角度:" << arc01normal01origin001 * 180.0 / Pild << "]_"; cou02t << "[arc1normal01" << arc1normal01 << "(角度:" << arc1normal01 * 180.0 / Pild << "] "; cou02t << "[reflecteAng01" << reflecteAng01 << "(反射角度:" << reflecteAng01 * 180.0 / Pild << "]" << endl; arc1arg02 = reflecteAng01; line2normal(hdc, reflecteAng01, old1X001,old1Y001, RGB(0,0,255), 6); //蓝色反射线 cou02t << "[arc1normal01:" << arc1normal01 << "]"; // system("pause"); goto lable220; }//if110elseif130 //不在小圆内,但在大圆内(第4块--特殊区域 else if (isInMoon(old1X001,old1Y001) && (!isInC2littlecircle(X001,Y001)&&isInC1BigCircle(X001,Y001) ) ) { lable910: //迭代找第1次,第一个弧的交点,即不在inInMoon内的第一个点 mid01X01 = (X001 + old1X001) / 2; mid01Y01 = (Y001 + old1Y001) / 2; if (isInMoon(mid01X01, mid01Y01)) { goto lable910; } else//注意此时,mid01X01,Y01不在Moon内了,已经 { X001 = mid01X01; Y01 = mid01Y01; //相当于退回中点(中值点 goto lable510; } }//if110elseif140 // //while (true); // }//void line01light02( ``` 完整代码: ``` // WinPro1moon01billiard181202a1.cpp : 定义应用程序的入口点。 #include "stdafx.h" #include "WinPro1moon01billiard181202a1.h" #include <iostream> #include <fstream> #include <iomanip> using namespace std; #define MAX_LOADSTRING 100 // 全局变量: //浮点数计PI(π): long double Pild = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196; HINSTANCE hInst; // 当前实例 WCHAR szTitle[MAX_LOADSTRING]; // 标题栏文本 WCHAR szWindowClass[MAX_LOADSTRING]; // 主窗口类名 ofstream cou02t; // 此代码模块中包含的函数的前向声明: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // TODO: 在此处放置代码。 //调用Console控制台 AllocConsole(); #pragma warning(disable:4996) _tfreopen(TEXT("CONOUT$"), TEXT("w"), stdout); _tfreopen(TEXT("CONOUT$"), TEXT("w"), stderr); _tfreopen(TEXT("CONIN$"), TEXT("r"), stdin); #pragma warning(default:4996) _tsetlocale(LC_ALL, TEXT("chs")); // cout << setprecision(99) << Pild << endl; // 初始化全局字符串 LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadStringW(hInstance, IDC_WINPRO1MOON01BILLIARD181202A1, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // 执行应用程序初始化: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WINPRO1MOON01BILLIARD181202A1)); MSG msg; // 主消息循环: while (GetMessage(&msg, nullptr, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam; } // // 函数: MyRegisterClass() // // 目标: 注册窗口类。 // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEXW wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINPRO1MOON01BILLIARD181202A1)); wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_WINPRO1MOON01BILLIARD181202A1); wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); return RegisterClassExW(&wcex); } // // 函数: InitInstance(HINSTANCE, int) // // 目标: 保存实例句柄并创建主窗口 // // 注释: // // 在此函数中,我们在全局变量中保存实例句柄并 // 创建和显示主程序窗口。 // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { hInst = hInstance; // 将实例句柄存储在全局变量中 HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } // int C2R200little = 200; int C2_X02little_pianyi400 = 400; int C2_Y02little_pianyi400 = 400; int Y_high600 = 600; int C1R1big400 = 400; int C1_X01big_pianyi400 = 400; int C1_Y01big_pianyi400 = 0;// 100; // double regularAngle(double ang1) { while (ang1 < -(Pild)) { ang1 + 2 * Pild; } while (ang1 > Pild) { ang1 - 2 * Pild; } return ang1; } // void setpixe02l(HDC hdc, int x, int y, COLORREF rgb1) { SetPixel(hdc, x, Y_high600 - y, rgb1); } void setpixe03l(HDC hdc, int x, int y, COLORREF rgb1 ,int R=3) { SetPixel(hdc, x, Y_high600 - y, rgb1); for (int i = 0; i < 360; ++i) { int x = R*cos(i); int y = R*sin(i); setpixe02l(hdc, x, y, rgb1); } } //专画法线 void line2normal(HDC hdc, double arc1, double x, double y, COLORREF rgb1, double R) { for (int i = 0; i < R; ++i) { int x001 = i * cos(arc1) + x; int y001 = i * sin(arc1) + y; setpixe02l(hdc, x001, y001, rgb1); } } // //计算欧氏(欧几里得)距离 double SquareOfEuclideanDistance(double x1, double x0, double y1, double y0) { return((x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0)); } // int isInC1BigCircle(double x1, double y1) { if (SquareOfEuclideanDistance(x1, 400, y1, 0) <= (400 * 400)) { return 1; } else return 0; } // int isInC2littlecircle(double x1, double y1) { if (SquareOfEuclideanDistance(x1, 400, y1, 400) <= (200 * 200)) { return 1; } else return 0; } //in Moon ,即在小圆,不在大圆里 int isInMoon(double x, double y) { if (1 == isInC2littlecircle(x, y) && 1 != isInC1BigCircle(x, y)) { return 1; } return 0; } // // void line01light02(HDC hdc, double arc1, unsigned long lineLen, double X01, double Y01) { // cou02t.open("f:/Cout181206cou02t_1202.txt"); double arc1arg02 = regularAngle(arc1); double X001 = X01; double Y001 = Y01; double X002 = X001; double Y002 = Y001; line2normal(hdc, arc1, X001, Y001, RGB(0, 200, 200), 10); cout << "[arc1arg01:" << arc1 << "]-"; cout << "[arc1arg02:" << arc1 << "]; "; unsigned long itime = 0; double old1X001 = X001; double old1Y001 = Y001; double mid01X01 = X001; double mid01Y01 = Y001; double arc01normal01origin001; double arc1normal01; double fanshe01Arc01; double reflecteAng01; double Xorigin01; double Yorigin01; // //循环光走(光线前进-简称光进)并反射等 //do { // lable110start: if (lineLen < 1) { return; } lable120: itime = 1; cou02t << "[itime:" << itime << "]_"; lable220: //开始算 反射角,并 (继续)光进 Xorigin01 = cos(arc1arg02)*(double)itime; Yorigin01 = sin(arc1arg02)*(double)itime; lable230: X001 = Xorigin01 + old1X001; Y001 = Yorigin01 + old1Y001; setpixe02l(hdc, X001, Y001, RGB(255, 25, 0));// , 255, 0));//绘图封装,封装都是有目的 的;没有目的 的“瞎封装”…会从我的小组被开除--Terry. lable510: //判断并(光线)步进: //if先判断是否在月亮形状里: (isInC2littlecircle && !isInC1BigCircle) if (isInMoon(X001, Y001)) {//if110 itime = 1; lineLen--; old1X001 = X001; old1Y001 = Y001; itime++; goto lable220; }//if110 //与小圆的上弧相交,else if下面判断:是否出了月亮,即出了小圆,(当然)也出了大圆 else if ( isInMoon(old1X001,old1Y001) && (1!=isInC2littlecircle(X001,Y001) && 1!=isInC1BigCircle(X001,Y001) ) ) { double arc01normal01origin01 = atan( (400-X001)/(Y001-400) ); arc1normal01 = Pild / 2.0 + arc01normal01origin01; line2normal(hdc, arc1normal01, old1X001, old1Y001, RGB(0, 100, 0), 5); //暗绿色法线 fanshe01Arc01 = arc1arg02 - 2 * arc1normal01; reflecteAng01=Pild - fanshe01Arc01; line2normal(hdc, reflecteAng01, old1X001, old1Y001, RGB(0, 255, 0), 6);//亮绿色反射线 arc1arg02 = reflecteAng01; cou02t << "[01-arc1normal01:" << arc1normal01 << "]"; // system("pause"); goto lable220; }else if ( isInMoon(old1X001,old1Y001) && (1==isInC2littlecircle(X001,Y001) && 1==isInC1BigCircle(X001,Y001) ) ) { cou02t << "Hell01!" << endl; //if110elseif120 //elseif下面判断:是否出了月亮,既然在小圆内,(但)仍然在大圆内(两圆相交处 //先规格、规范化入射角: double arc1ang03=arc1arg02; // arc1ang03= regularAngle(arc1arg02); while (arc1ang03 > Pild) { arc1ang03 =arc1ang03- 2 * Pild; } while (arc1ang03 < -Pild) { arc1ang03 = arc1ang03 + 2*Pild; } //arc01normal01origin001 = atan((-400 +X001 / (Y001 - 0) ) ); arc01normal01origin001 = asin((-X001 + 400) / 400); arc1normal01 = Pild/2.0+ arc01normal01origin001;//(/*Pild / 2.0*/ - arc01normal01origin001); // line2normal(hdc, arc1normal01, old1X001, old1Y001, RGB(0, 200,0), 15); //暗Green法线 line2normal(hdc, Pild+arc1normal01, old1X001, old1Y001, RGB(0, 200, 0), 395); //暗Green法线 fanshe01Arc01 = Pild+arc1ang03 - 2 * arc1normal01; reflecteAng01 = -fanshe01Arc01; cou02t << "Hello!" << endl; cou02t << endl << "[入射角arc1arg02:" << arc1arg02 << "(角度:" << arc1arg02 * 180.0 / Pild << "]_"; cou02t << endl << "[入射角规范化arc1ang03:" << arc1ang03 << "(角度:" << arc1ang03 * 180.0 / Pild << "]_"; cou02t << endl<<"[法线arc01normal01origin001" << arc01normal01origin001 << "(角度:" << arc01normal01origin001 * 180.0 / Pild << "]_"; cou02t << "[arc1normal01" << arc1normal01 << "(角度:" << arc1normal01 * 180.0 / Pild << "] "; cou02t << "[reflecteAng01" << reflecteAng01 << "(反射角度:" << reflecteAng01 * 180.0 / Pild << "]" << endl; arc1arg02 = reflecteAng01; line2normal(hdc, reflecteAng01, old1X001,old1Y001, RGB(0,0,255), 6); //蓝色反射线 cou02t << "[arc1normal01:" << arc1normal01 << "]"; // system("pause"); goto lable220; }//if110elseif130 //不在小圆内,但在大圆内(第4块--特殊区域 else if (isInMoon(old1X001,old1Y001) && (!isInC2littlecircle(X001,Y001)&&isInC1BigCircle(X001,Y001) ) ) { lable910: //迭代找第1次,第一个弧的交点,即不在inInMoon内的第一个点 mid01X01 = (X001 + old1X001) / 2; mid01Y01 = (Y001 + old1Y001) / 2; if (isInMoon(mid01X01, mid01Y01)) { goto lable910; } else//注意此时,mid01X01,Y01不在Moon内了,已经 { X001 = mid01X01; Y01 = mid01Y01; //相当于退回中点(中值点 goto lable510; } }//if110elseif140 // //while (true); // }//void line01light02(HDC hdc, double arc1, unsigned long linelen, double x0, double y0 // // void wm01paint01(HDC hdc) { //画2圆: //画小圆Circle02: for (int i = 0; i < 361; ++i) { double arc02 = i * Pild / 180; int x02little = cos(arc02)*C2R200little + C2_X02little_pianyi400; int y02little = sin(arc02)*C2R200little + C2_Y02little_pianyi400; setpixe02l(hdc, x02little, y02little, RGB(0, 100, 0) ); } //画大圆Circle01: for (int i = 0; i < 10*350; ++i) { double arc01 = i * Pild / 180 /10; int x02big = cos(arc01)*C1R1big400 + C1_X01big_pianyi400; int y02big = sin(arc01)*C1R1big400 + C1_Y01big_pianyi400; setpixe02l(hdc, x02big, y02big, RGB(0, 100, 0)); } double arc1; //输入初始参数: arc1 = (-3.0 / 16.0)*Pild; int x1 = 290; int y1 = 410; line01light02(hdc, arc1, 19, x1,y1); //参数说明: hdc绘图板,入射角arc1= 7/16PI, x1=300,y1=410为入射光线初始坐标 setpixe02l(hdc, 1 + x1, 1 + y1, RGB(0, 0, 255)); setpixe03l(hdc, x1, y1, RGB(0, 0, 255),5); }//void wm01paint01(HDC hdc // 函数: WndProc(HWND, UINT, WPARAM, LPARAM) // // 目标: 处理主窗口的消息。 // // WM_COMMAND - 处理应用程序菜单 // WM_PAINT - 绘制主窗口 // WM_DESTROY - 发送退出消息并返回 // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COMMAND: { int wmId = LOWORD(wParam); // 分析菜单选择: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } } break; case WM_PAINT: {//case110 PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); // TODO: 在此处添加使用 hdc 的任何绘图代码... wm01paint01(hdc); EndPaint(hWnd, &ps); }//case110 break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // “关于”框的消息处理程序。 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG: return (INT_PTR)TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; } break; } return (INT_PTR)FALSE; } ```