助力软件开发企业降本增效 PHP / java源码系统,只需一次付费,代码终身使用! 广告
``` // Project1clzz002billiard181010b2.cpp : 定义应用程序的入口点。 // #include "stdafx.h" #include "Project1clzz002billiard181010b2.h" #include <iostream> #include <iomanip> #include <fstream> using namespace std; #define MAX_LOADSTRING 100 // 全局变量: long RecursionTimes = 0; //浮点数计PI(π): long double Pild = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196; //输出有效为: 3.141592653589793115997963468544185161590576171875 //有效位: 3.141592653589793 //等价 //PILD01=3.141592653589793; long double Pi2ld = 3.1415926535897932; // uint64_t PI_uint64t = 3141592653589793238; //31415926535897932384;//整数常量太大 uint64_t halfPI_uint64t = 15707963267948966192; // halfPI=90度; 157079632679489661923;整数常量太大 uint64_t hPi = 15707963267948966192;// halfPI=90度; // int C1_200_R01 = 400;//大圆半径(又称1号圆半径) int C2_200_R02 = 200;//小圆半径又称2号圆 int c1Bpianyi_B1 = 0; //大圆用初始值-(圆心的偏移量横坐标-上下坐标(暂时)为0 int c1Apianyi_A1 = 400;//大圆圆心位置-坐标(左右坐标 int C1x00a = 400; int C1y00b = 0; int c2Bpianyi_B2 = 300;//小圆圆心位置-上下坐标 int c2Apianyi_A2 = 400;//小圆圆心位置-左右坐标 int C2x00a = 400;int C2y00b = 300; int c1C2_Distance = 300;//两圆圆心间距 //ofstream cou02t; //cou02t.open("f://ou18t_cou02t181110.txt"); // //文件流操作 //ofstream outStream; //ofstream outStrea0m2; //ofstream outStrea0m3; //outStream.open("f://out18File001.txt"); ofstream cou02t; //cou02t.open("f://ou18t_cou02t181110.txt"); // HINSTANCE hInst; // 当前实例 WCHAR szTitle[MAX_LOADSTRING]; // 标题栏文本 WCHAR szWindowClass[MAX_LOADSTRING]; // 主窗口类名 // struct Position0old1 { //定义交点位置 int a1; int b1; } p0old1, p0old2; struct Position001 { //定义交点位置 double c1angle; //角度 double c2angle; double a1; //坐标 double b2; }; Position001 P01 = { 61.045, 14.478}; Position001 P02 = { 118.955, 165.522 }; // 此代码模块中包含的函数的前向声明: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); double RegularAngleRad0_2PI(double rad1) { // cou02t << "[rad1:"<<rad1 <<"]"<< endl; long double tmpAngle = (rad1 * 180) / PIld; // cou02t << "tmpAngle:" << tmpAngle << "]" << endl; long long tmp2 = 1000 * tmpAngle; double rad2 = (double)( (long)tmp2 % (360000) ); // cou02t << "rad2:" << rad2 << "]" << endl; while(rad2<0) { rad2 += 360000; }; // while (rad2 < 0); double rad3 = rad2 / 180 * PIld /1000; return rad3; }//double RegularAngleRad0_2PI 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; // //测试函数 double rad01 = ((double)1.0 / 2) * PIld; //4 * PIld;// 3 * PIld; double rad02 = RegularAngleRad0_2PI(rad01); cout << "[rad02:"; cout << endl; rad01 = -(1.0 / 2)*PIld; cout << "[rad02:"; rad02 = RegularAngleRad0_2PI(rad01); cout << rad02 << endl; // rad01 = -(1.0 / 8)*PIld; cout << "[rad02:"; rad02 = RegularAngleRad0_2PI(rad01); cout << rad02 << endl; // rad01 = (17.0 / 8)*PIld; cout << "[rad02:"; rad02 = RegularAngleRad0_2PI(rad01); cout << rad02 << endl; // cout << setprecision(99) << Pi2ld << endl; // //打开日志文件 //ofstream cou02t; cou02t.open("f://out18cou02t181110.txt"); //打开日志文件-End // 初始化全局字符串 LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadStringW(hInstance, IDC_PROJECT1CLZZ002BILLIARD181010B2, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // 执行应用程序初始化: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PROJECT1CLZZ002BILLIARD181010B2)); 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_PROJECT1CLZZ002BILLIARD181010B2)); wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_PROJECT1CLZZ002BILLIARD181010B2); 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; } // // //p01 定义:当1号圆(大圆)在上的时候,0度位置(右侧)的为p01,左侧为p02 // 当1号圆(大圆)在左的时候,90度位置(上方)的为p01,下方:270度位置为p02 // long double EduclidDistanceOrWhethShortest(long double x1, long double y1, long double x2, long double y2) {//33000 long double tmp_ld = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2); return (tmp_ld ); }//33000 // //为图形旋转、变形、做的封装 int SetPixe01d(HDC hdc, double x01, double y01, COLORREF rgb1) { SetPixel(hdc, x01, 700-y01, rgb1);// return 1; }//int SetPixe02 //为图形旋转、变形、做的封装 int SetPixe01d_old1(HDC hdc, double x01, double y01, COLORREF rgb1) { SetPixel(hdc, x01, 700 - y01, rgb1);// return 1; }//int SetPixe02 // //此处封装纯为翻转、旋转图形用 int MoveToE02x(HDC hdc, int x, int y, LPPOINT lppt) { MoveToEx(hdc, x, 700-y, NULL); return 1; }//int MoveToE02x // int LineT02o(HDC hdc, int x, int y) { LineTo(hdc, x, 700-y); return 1; }//int LineT2o; // //判断是否在圆内,在圆内返回正数,相碰返回0,在圆外返回负数 int whetherThisPixelIsInC2(double a, double b, double X00, double Y00, double r) { long double tmpEuclid = (a - X00)*(a - X00) + (b - Y00)*(b - Y00); long double Rr2 = r * r; if ((Rr2) > tmpEuclid) return ( (long)(Rr2 - tmpEuclid) );//正值在圆内 else if (Rr2 < tmpEuclid) return ((int)(Rr2 - tmpEuclid));//负值,在圆外 else return 0; return 1; } //判断是否在圆内,在圆内返回正数,相碰返回0,在圆外返回负数 int whetherThisPixelIsInC1(double a, double b, double X00, double Y00, double r) { long double tmpEuclid = (a - X00)*(a - X00) + (b - Y00)*(b - Y00); long double Rr1 = r * r; if ((Rr1) > tmpEuclid) return ((long)(Rr1 - tmpEuclid));//正值在圆内(欧氏距离的平方 else if (Rr1 < tmpEuclid) return ((int)(Rr1 - tmpEuclid));//负值,在圆外 else return 0; return 1; } //专画法线 int light2normaLine(HDC hdc,double arcs, int lineLen, int x0, int y0, COLORREF rgbcolor) { int lineLen01 = lineLen;// 199; for (int i = 0; i < lineLen01; ++i) { int x1 = i*cos(arcs) + x0; int y1 = i*sin(arcs) + y0; SetPixe01d(hdc, x1, y1, rgbcolor ); } return 1; }//int light2normaLine // //绘制()光线 // int c2Bpianyi_B2 = 300;//小圆圆心位置-上下坐标 // int c2Apianyi_A2 = 400;//小圆圆心位置-左右坐标 //light2Circle01参数: 0:HDC hdc; 1:int whichCircleNum先碰哪个圆 2:光线长度long long; 3:发光角度(弧度如0~PIπ)为射向小圆2号圆;4:光源A坐标;5:光源B坐标) int light2Circl0e1(double rad01, HDC hdc, int whichCircleNum, long lightLen, double A1, double B1) { // ofstream cou02t; // cou02t.open("f://out18cou02t181110.txt"); RecursionTimes++; cou02t << "[RecursionTimes:"<< RecursionTimes << "]" << endl; cou02t << "[原始入射角:" << rad01; double rad002 = RegularAngleRad0_2PI(rad01); cou02t << "{规格化后的入射角(弧度):" << rad002 << "}"; cou02t << "[角度:" << rad002 * 180 / PIld << "]"; cou02t<< endl; long long lightLen001 = lightLen; // do {//do110 //for (long long ii = 1; ii < lightLen001; ++ii) {//for210 注意:如果 for(long long ii=0 从0开始就停在原地 永远(死)循环了…… for (long long ii = 1; ii < lightLen001; ++ii) {//for210 --lightLen001; //if (ii > lightLen001) break; double a01 = ii * cos(rad002); double b01 = ii * sin(rad002); double realA001 = a01 + A1; double realB001 = b01 + B1; cou02t << "[realA001:" << realA001 << "]"; cou02t << "[realB001:" << realB001 << "]" << endl; SetPixe01d(hdc, realA001, realB001, RGB(201, 0, 0));// 0, 255, 0)); //特殊情况,原始入射角为0 // Position001 P01 = { 61.045, 14.478 }; // Position001 P02 = { 118.955, 165.522 }; // if (realA001 > 118.955 +400 ) { realA001 = 118.954+400; } if (realA001 > 600) { realA001 = 580; } if (realB001 <351) { realB001 = 360; } // if (realB001 > 165.522) { realB001 = 165.521; } if (0 == rad01) { double rad00101 = PIld+0.01; light2Circl0e1(rad00101, hdc, 1, (long)9, realA001, realB001); } // //判断是否和两CircleS相交: //判断和Circle02相交与否 //先判断 点 是否仍然在 C2内 int isInC2true=whetherThisPixelIsInC2(realA001, realB001, C2x00a, C2y00b, C2_200_R02); //a01,b01当前点, C1x00a,c1y00b小圆圆心,C2_200_R02小圆半径 int isInC1true = whetherThisPixelIsInC1(realA001, realB001, C1x00a, C1y00b, C1_200_R01); //a01,b01当前点, C1x00a,c1y00b小圆圆心,C2_200_R02小圆半径 if((isInC2true <= 0) || (isInC1true > 0)) //SetPixel {//判断和Circle02相交与否代码块 //判断光线是否碰(或进入C1大圆Circle01: // int isInC1true = whetherThisPixelIsInC1(realA001, realB001, C1x00a, C1y00b, C1_200_R01); //a01,b01当前点, C1x00a,c1y00b小圆圆心,C2_200_R02小圆半径 if (isInC1true > 0) //第1(第二)...大于0则碰撞或者进大圆(C1)了! {//if3550 // //算与大圆碰撞的代码块 {//算与大圆碰撞的代码块 //规范化入射角到90度之内 double rad0003 = 0; if (rad002 > (PIld*3.0 / 2)) { rad0003 = rad002 - PIld * 3.0 / 2; } else { rad0003 = PIld * 3.0 / 2 - rad002; } double rad004 = 2.0*PIld - rad002; //这是算原本(法线为90度时)的反射线; //算法线角(弧度 //先算法线: MoveToE02x(hdc, realA001, realB001, NULL); // LineT02o(hdc, C1x00a, C1y00b); //演示法线的辅助线,用于检验法线是否标准 double normAngleArcs2 = 0; //if( C1x00a>realA001 ) normAngleArcs2 = acos((double)(C1x00a - realA001) / C1_200_R01); //else { normAngleArcs2 = acos((double)(realA001 -C1x00a ) / C1_200_R01); } // cou02t << "[normAngleArcs(规范前:" << normAngleArcs2 << "]"; // cou02t << "{法线角度:" << normAngleArcs2 * 180 / (PIld) << "}"; double regula90_normAnglearcs002 = PIld * 1.0 / 2 - normAngleArcs2; //90度-减法线角度,就是规格化法线 // cou02t << "[法线normAngleArcs(规格到90度内:" << regula90_normAnglearcs002 << "]"; // cou02t << "{法线角度:" << regula90_normAnglearcs002 * 180 / (PIld) << "}"; // cou02t << "[(当前)入射角(规范化前:" << rad002 << "]"; // cou02t << "{入射角度:" << rad002 * 180 / (PIld) << "}" << endl; // cou02t << "[(当前)入射角(规范到90度内:" << rad0003 << "]"; // cou02t << "{入射角度:" << rad0003 * 180 / (PIld) << "}" << endl; //法线-绿色 // //light2normaLine(hdc, normAngleArcs2, 99, realA001, realB001, RGB(0, 200, 0));//绿色法线 //法线-绿色end //计算反射角(弧度 //-Pild取反方向,再加 double regula_incidenceAngleMinusTwotimestheNormAngleArcs2 = 0; double incidenceAngleMinusTwotimestheNormAngleArcs2 = 0;// rad01 + 2 * (normAngleArcs2); incidenceAngleMinusTwotimestheNormAngleArcs2 = rad004 + 2 * regula90_normAnglearcs002; //这是算有法线,加(或减)个小角度 // cou02t << "[(当前)反射角:" << incidenceAngleMinusTwotimestheNormAngleArcs2 << "]"; // cou02t << "{反射角度:" << incidenceAngleMinusTwotimestheNormAngleArcs2 * 180 / (PIld) << "}" << endl; //double regula_incidenceAngleMinusTwotimestheNormAngleArcs2 = RegularAngleRad0_2PI(incidenceAngleMinusTwotimestheNormAngleArcs2); // cou02t << "[规范后(当前)反射角:" << regula_incidenceAngleMinusTwotimestheNormAngleArcs2<< "]"; // cou02t << "{规范后反射角度:" << regula_incidenceAngleMinusTwotimestheNormAngleArcs2 * 180 / (PIld) << "}" << endl; // light2normaLine(hdc, incidenceAngleMinusTwotimestheNormAngleArcs2, 59, realA001, realB001, RGB(0, 200, 0));//绿色测试法线线 light2Circl0e1(incidenceAngleMinusTwotimestheNormAngleArcs2, hdc, 1, (long)lightLen001, realA001, realB001); }//算与大圆碰撞的代码块-end //算与大圆碰撞的代码块-end }//if3550 else //第2(第二)...//if (isInC2true <= 0) //与 C2相碰撞了(或碰撞过了) {//if318/ {//计算小圆C2碰撞得反射线-代码块 //先算法线: MoveToE02x(hdc, realA001, realB001, NULL); // LineT02o(hdc, C2x00a, C2y00b); //算法线角(弧度 double normAngleArcs1 = -acos( (double)(C2x00a-realA001) / C2_200_R02); // cou02t << "[normAngleArcs:" << normAngleArcs1 << "]"; // cou02t << "{法线角度:" << normAngleArcs1 * 180 / (PIld) << "}"; // cou02t << "[(当前)入射角:" << rad002 << "]" ; // cou02t << "{入射角度:" << rad002 * 180 / (PIld) << "}"<< endl; //法线-绿色 // light2normaLine(hdc, normAngleArcs1, 19, realA001, realB001, RGB(0,200,0) );//绿色法线 标志181122 //法线-绿色end //入射角-2倍的法线: double incidenceAngleMinusTwotimestheNormAngleArcs = rad002 - (2* normAngleArcs1); // cou02t << "[(当前)反射角:" << incidenceAngleMinusTwotimestheNormAngleArcs << "]"; // cou02t << "{反射角度:" << incidenceAngleMinusTwotimestheNormAngleArcs * 180 / (PIld) << "}" << endl; double regula_incidenceAngleMinusTwotimestheNormAngleArcs = RegularAngleRad0_2PI(incidenceAngleMinusTwotimestheNormAngleArcs); // cou02t << "[规范后(当前)反射角:" << regula_incidenceAngleMinusTwotimestheNormAngleArcs << "]"; // cou02t << "{规范后反射角度:" << regula_incidenceAngleMinusTwotimestheNormAngleArcs * 180 / (PIld) << "}" << endl; // light2normaLine(hdc, regula_incidenceAngleMinusTwotimestheNormAngleArcs, 59, realA001, realB001, RGB(0, 200,0));//绿色测试线 light2Circl0e1(regula_incidenceAngleMinusTwotimestheNormAngleArcs, hdc, 1, (long )999, realA001, realB001); //法线加反射角等于反射矢量角 }//计算小圆C2碰撞得反射线-代码块-end //light2Circl0e1(hdc, 1, lightLen001, 反射线角度, a01,b01); } //if318 }//判断和Circle01相交与否代码块end //判断和Circle01相交与否-End else { //剩余情况 // // if ((isInC1true <= 0) && (isInC2true <= 0)) {//剩余情况1 {//算与大圆碰撞的代码块 //规范化入射角到90度之内 double rad0003 = 0; if (rad002 > (PIld*3.0 / 2)) { rad0003 = rad002 - PIld * 3.0 / 2; } else { rad0003 = PIld * 3.0 / 2 - rad002; } double rad004 = 2.0*PIld - rad002; //这是算原本(法线为90度时)的反射线; //算法线角(弧度 //先算法线: MoveToE02x(hdc, realA001, realB001, NULL); // LineT02o(hdc, C1x00a, C1y00b); //演示法线的辅助线,用于检验法线是否标准 double normAngleArcs2 = 0; //if( C1x00a>realA001 ) normAngleArcs2 = acos((double)(C1x00a - realA001) / C1_200_R01); //else { normAngleArcs2 = acos((double)(realA001 -C1x00a ) / C1_200_R01); } // cou02t << "[normAngleArcs(规范前:" << normAngleArcs2 << "]"; // cou02t << "{法线角度:" << normAngleArcs2 * 180 / (PIld) << "}"; double regula90_normAnglearcs002 = PIld * 1.0 / 2 - normAngleArcs2; //90度-减法线角度,就是规格化法线 // cou02t << "[法线normAngleArcs(规格到90度内:" << regula90_normAnglearcs002 << "]"; // cou02t << "{法线角度:" << regula90_normAnglearcs002 * 180 / (PIld) << "}"; // cou02t << "[(当前)入射角(规范化前:" << rad002 << "]"; // cou02t << "{入射角度:" << rad002 * 180 / (PIld) << "}" << endl; // cou02t << "[(当前)入射角(规范到90度内:" << rad0003 << "]"; // cou02t << "{入射角度:" << rad0003 * 180 / (PIld) << "}" << endl; // light2normaLine(hdc, normAngleArcs2, 99, realA001, realB001, RGB(0, 200, 0));//绿色法线 //计算反射角(弧度 //-Pild取反方向,再加 double regula_incidenceAngleMinusTwotimestheNormAngleArcs2 = 0; double incidenceAngleMinusTwotimestheNormAngleArcs2 = 0;// rad01 + 2 * (normAngleArcs2); incidenceAngleMinusTwotimestheNormAngleArcs2 = rad004 + 2 * regula90_normAnglearcs002; //这是算有法线,加(或减)个小角度 // cou02t << "[(当前)反射角:" << incidenceAngleMinusTwotimestheNormAngleArcs2 << "]"; // cou02t << "{反射角度:" << incidenceAngleMinusTwotimestheNormAngleArcs2 * 180 / (PIld) << "}" << endl; //double regula_incidenceAngleMinusTwotimestheNormAngleArcs2 = RegularAngleRad0_2PI(incidenceAngleMinusTwotimestheNormAngleArcs2); // cou02t << "[规范后(当前)反射角:" << regula_incidenceAngleMinusTwotimestheNormAngleArcs2<< "]"; // cou02t << "{规范后反射角度:" << regula_incidenceAngleMinusTwotimestheNormAngleArcs2 * 180 / (PIld) << "}" << endl; // light2normaLine(hdc, incidenceAngleMinusTwotimestheNormAngleArcs2, 59, realA001, realB001, RGB(0, 200, 0));//绿色测试法线线 light2Circl0e1(incidenceAngleMinusTwotimestheNormAngleArcs2, hdc, 1, (long)lightLen001, realA001, realB001); }//算与大圆碰撞的代码块-end }//剩余情况1-end // if ((isInC1true <= 0) && (isInC2true <= 0)) //{//剩余情况2if ((isInC1true >= 0) && (isInC2true <= 0)) // { // } // else // if ((isInC1true <= 0) && (isInC2true <= 0)) {//剩余情况2if ((isInC1true >= 0) && (isInC2true <= 0)) {//计算小圆C2碰撞得反射线-代码块 //先算法线: MoveToE02x(hdc, realA001, realB001, NULL); // LineT02o(hdc, C2x00a, C2y00b); //算法线角(弧度 double normAngleArcs1 = -acos((double)(C2x00a - realA001) / C2_200_R02); // cou02t << "[normAngleArcs:" << normAngleArcs1 << "]"; // cou02t << "{法线角度:" << normAngleArcs1 * 180 / (PIld) << "}"; // cou02t << "[(当前)入射角:" << rad002 << "]" ; // cou02t << "{入射角度:" << rad002 * 180 / (PIld) << "}"<< endl; light2normaLine(hdc, normAngleArcs1, 19, realA001, realB001, RGB(0, 200, 0));//绿色法线 //入射角-2倍的法线: double incidenceAngleMinusTwotimestheNormAngleArcs = rad002 - (2 * normAngleArcs1); // cou02t << "[(当前)反射角:" << incidenceAngleMinusTwotimestheNormAngleArcs << "]"; // cou02t << "{反射角度:" << incidenceAngleMinusTwotimestheNormAngleArcs * 180 / (PIld) << "}" << endl; double regula_incidenceAngleMinusTwotimestheNormAngleArcs = RegularAngleRad0_2PI(incidenceAngleMinusTwotimestheNormAngleArcs); // cou02t << "[规范后(当前)反射角:" << regula_incidenceAngleMinusTwotimestheNormAngleArcs << "]"; // cou02t << "{规范后反射角度:" << regula_incidenceAngleMinusTwotimestheNormAngleArcs * 180 / (PIld) << "}" << endl; // light2normaLine(hdc, regula_incidenceAngleMinusTwotimestheNormAngleArcs, 59, realA001, realB001, RGB(0, 200,0));//绿色测试线 light2Circl0e1(regula_incidenceAngleMinusTwotimestheNormAngleArcs, hdc, 1, (long)999, realA001, realB001); //法线加反射角等于反射矢量角 }//计算小圆C2碰撞得反射线-代码块-end }//剩余情况-End_if ((isInC1true >= 0) && (isInC2true <= 0)) else { //cout << ii<<endl; cou02t<<endl << "_[" << ii << "]";// // //这里处理入射角已经等于0的情况 //先按照小圆内处理 if (0 == rad01) { double rad00101 = 3.1415926; light2Circl0e1(rad00101 , hdc, 1, (long)1, realA001, realB001); } // } // continue; // // }//剩余情况 }//for210 // } while (lightLen001 > 0);//do110 return 1; }//int light2Circle01 //绘制光线-End // //绘制(初始)光线 //light2Circle001参数: 0:HDC hdc; 1:int whichCircleNum先碰哪个圆 2:光线长度long long; 3:发光角度(弧度如0~PIπ)为射向小圆2号圆;4:光源A坐标;5:光源B坐标) int light2Circle001(HDC hdc, int whichCircleNum, long long lightLen, double rad01, int A1, int B1) { long long lightLen001 = lightLen; for (long ii = 0; ii < 29; ++ii) { if (ii > lightLen001) break; int a01 = ii * cos(rad01); int b01 = ii * sin(rad01); SetPixe01d(hdc, 1+A1+a01, -1+B1+b01, RGB(0, 127, 0)); } //延长画线 //正式开始画线 light2Circl0e1(rad01, hdc, 2, lightLen, A1, B1); return 1; }//int light2Circle01 //绘制初始光线-End // //重新绘图函数模块: int wm01paint01(HWND hWnd, PAINTSTRUCT ps, HDC hdc) {//int wm01paint01 //1100 // // int C1_200_R01 = 400;//大圆半径(又称1号圆半径) // int C2_200_R02 = 200;//小圆半径又称2号圆 // int c1Bpianyi_B1 = 0; //大圆用初始值-(圆心的偏移量横坐标-上下坐标(暂时)为0 // int c1Apianyi_A1 = 400;//大圆圆心位置-坐标(左右坐标 // int c2Bpianyi_B2 = 300;//小圆圆心位置-上下坐标 // int c2Apianyi_A2 = 400;//小圆圆心位置-左右坐标 // int c1C2_Distance = 300;//两圆圆心间距 // //文件流操作 // ofstream outStream; // ofstream outStrea0m2; // ofstream outStrea0m3; // outStream.open("f://out18File001.txt"); // outStrea0m2.open("f://out18File002a1.txt"); // outStrea0m3.open("f://out18File003.txt"); // // //画两圆轮廓 //大圆 for (int i1 = 0; i1 < 181*2; ++i1) { double c1_rad1 = (double)PIld*((double)i1 / 180.0) /2;// / 1000; double c1_a001 = C1_200_R01 * cos(c1_rad1); //int c1_a001 = C1_200_R01 * cos(c1_rad1); double c1_b001 = C1_200_R01 * sin(c1_rad1); SetPixe01d(hdc, c1Apianyi_A1 + c1_a001, c1Bpianyi_B1 + c1_b001, RGB(200, 200, 0));// 228, 0));//黄 } // //小圆 for (int i1 = 0; i1 < 351 * 2; ++i1) { double c2_rad02 = (double)PIld*((double)i1 / 180.0) / 2;// / 1000; double c2_a002 = C2_200_R02 * cos(c2_rad02); //int c1_a001 = C1_200_R01 * cos(c1_rad1); double c2_b002 = C2_200_R02 * sin(c2_rad02); SetPixe01d(hdc, c2Apianyi_A2 + c2_a002, c2Bpianyi_B2 + c2_b002, RGB(200, 200, 0));// 228, 0));//黄 } // //找交点,P1 /* { //找P1交点 long double Shortest_euclidDistance001 = 999999999999999.8751; //99999 99999 99999.875f是精确表达上限(小数点前15个9 //迭代、逼近找两圆交点 // for (long i1 = 60.93*1000; i1 <= 61.95*1000; ++i1) {//for1100i1 //根据极坐标参数求笛卡尔直角坐标点: long double c1_rad1 = (long double)PIld*((long double)i1 / 180.0) /1000; long double c1_a001 = C1_200_R01 * cos(c1_rad1); //int c1_a001 = C1_200_R01 * cos(c1_rad1); long double c1_b001 = C1_200_R01 * sin(c1_rad1); // for (long j2 = 14.46*1000; j2 <= 14.49*1000; ++j2) {//for2100j2 long double c2_rad02 = (long double)PIld *((long double)j2 / 180.0)/1000; long double c2_a001 = C2_200_R02 * cos(c2_rad02); //int c2_a001 = C2_200_R02 * cos(c2_rad02); long double c2_b002 = C2_200_R02 * sin(c2_rad02); //两个坐标的4个值取精度,后比较 long double doub_c1_a001 = (long double)c1Apianyi_A1 * 10000 + ((long double)c1_a001 * 10000); //最高不要超过15个0 long double doub_c1_b001 = c1Bpianyi_B1 * 10000 + c1_b001 * 10000; long double doub_c2_a001 = c2Apianyi_A2 * 10000 + c2_a001 * 10000; long double doub_c2_b002 = c2Bpianyi_B2 * 10000 + c2_b002 * 10000; outStream << "[C1rad:" << c1_rad1 << "]:"; outStream << "{C1角度:" << i1 << "}"; outStream << "[坐标c1A1:" << doub_c1_a001 << "]"; outStream << "[c1B1:" << doub_c1_b001 << "]"; outStream << "[C2rad2:" << c2_rad02 << "]:"; outStream << "{C2角度:" << j2 << "]"; outStream << "[c2A1:" << doub_c2_a001 << "]"; outStream << "[c2B1:" << doub_c2_b002 << "]" << endl; long double tmpEduclidDist01 = EduclidDistanceOrWhethShortest(doub_c1_a001, doub_c1_b001, doub_c2_a001, doub_c2_b002); outStream << "{欧氏距离:" << tmpEduclidDist01 << "}" << endl; // EduclidDistanceOrWhethShortest参数 (x1,y1,x2,y2); if (Shortest_euclidDistance001 > tmpEduclidDist01) {//if2100 Shortest_euclidDistance001 = tmpEduclidDist01; // outStrea0m2 << "[C1rad:" << c1_rad1 << "]:"; outStrea0m2 << "{C1角度:" << i1 << "}"; outStrea0m2 << "[坐标c1A1:" << doub_c1_a001 << "]"; outStrea0m2 << "[c1B1:" << doub_c1_b001 << "]"; outStrea0m2 << "[C2rad2:" << c2_rad02 << "]:"; outStrea0m2 << "{C2角度:" << j2 << "]"; outStrea0m2 << "[c2A1:" << doub_c2_a001 << "]"; outStrea0m2 << "[c2B1:" << doub_c2_b002 << "]" << endl; outStrea0m2 << "{欧氏距离:" << tmpEduclidDist01 << "}" << endl; SetPixe01d(hdc, c2Apianyi_A2 + c2_a001, c2Bpianyi_B2 + c2_b002, RGB(255, 200, 0)); //绿色 // }//if2100 else {//if2100else2100 SetPixe01d(hdc, c2Apianyi_A2 + c2_a001, c2Bpianyi_B2 + c2_b002, RGB(0, 200, 0)); //绿色 }//if2100else2100 }//for2100j2 //绘制大圆(或外圆) SetPixe01d(hdc, c1Apianyi_A1 + c1_a001, c1Bpianyi_B1 + c1_b001, RGB(200, 200, 0));// 228, 0));//黄 // }//for1100i1// //(阶段)结果: //[C1rad:1.06535]:{C1角度:6104}[坐标c1A1:5.9368e+06][c1B1:3.49983e+06][C2rad2:0.252549]:{C2角度:14.47][c2A1:5.93656e+06][c2B1:3.49975e+06] //{欧氏距离:64181.4} //再迭代: //[C1rad:1.06544]:{C1角度:61.045}[坐标c1A1:5.93649e+06][c1B1:3.5e+06][C2rad2:0.252689] : {C2角度:14.478][c2A1:5.93649e+06][c2B1:3.50002e+06]{ 欧氏距离:253.008 } //结果,收敛和吻合得很好 //C1:61.045(角度) C2:14.478 就是答案 }//找交点P1-结束 */ //继续找交点 //找交点P2: {//找交点P2代码块110 //找交点P2 /* ofstream outStrea02m002b; outStrea02m002b.open("f://out18File1012b002b.txt"); long double Shortest_euclidDistance002 = 999999999999999.8751; //99999 99999 99999.875f是精确表达上限(小数点前15个9 //迭代、逼近找两圆交点 // for (long i1 = 118.954*1000; i1 <= 118.956*1000; ++i1) {//for1100i1 //根据极坐标参数求笛卡尔直角坐标点: long double c1_rad1 = (long double)PIld*((long double)i1 / 180.0)/1000; long double c1_a001 = C1_200_R01 * cos(c1_rad1); //int c1_a001 = C1_200_R01 * cos(c1_rad1); long double c1_b001 = C1_200_R01 * sin(c1_rad1); // for (long j2 = 165.521*1000; j2 <=165.523 *1000; ++j2) {//for2100j2 long double c2_rad02 = (long double)PIld *((long double)j2 / 180.0)/1000; long double c2_a001 = C2_200_R02 * cos(c2_rad02); //int c2_a001 = C2_200_R02 * cos(c2_rad02); long double c2_b002 = C2_200_R02 * sin(c2_rad02); //两个坐标的4个值取精度,后比较 long double doub_c1_a001 = (long double)c1Apianyi_A1 * 10000 + ((long double)c1_a001 * 10000); //最高不要超过15个0 long double doub_c1_b001 = c1Bpianyi_B1 * 10000 + c1_b001 * 10000; long double doub_c2_a001 = c2Apianyi_A2 * 10000 + c2_a001 * 10000; long double doub_c2_b002 = c2Bpianyi_B2 * 10000 + c2_b002 * 10000; outStream << "[C1rad:" << c1_rad1 << "]:"; outStream << "{C1角度:" << i1 << "}"; outStream << "[坐标c1A1:" << doub_c1_a001 << "]"; outStream << "[c1B1:" << doub_c1_b001 << "]"; outStream << "[C2rad2:" << c2_rad02 << "]:"; outStream << "{C2角度:" << j2 << "]"; outStream << "[c2A1:" << doub_c2_a001 << "]"; outStream << "[c2B1:" << doub_c2_b002 << "]" << endl; long double tmpEduclidDist01 = EduclidDistanceOrWhethShortest(doub_c1_a001, doub_c1_b001, doub_c2_a001, doub_c2_b002); outStream << "{欧氏距离:" << tmpEduclidDist01 << "}" << endl; // EduclidDistanceOrWhethShortest参数 (x1,y1,x2,y2); if (Shortest_euclidDistance002 > tmpEduclidDist01) {//if2100 Shortest_euclidDistance002 = tmpEduclidDist01; // outStrea02m002b << "[C1rad:" << c1_rad1 << "]:"; outStrea02m002b << "{C1角度:" << i1 << "}"; outStrea02m002b << "[坐标c1A1:" << doub_c1_a001 << "]"; outStrea02m002b << "[c1B1:" << doub_c1_b001 << "]"; outStrea02m002b << "[C2rad2:" << c2_rad02 << "]:"; outStrea02m002b << "{C2角度:" << j2 << "]"; outStrea02m002b << "[c2A1:" << doub_c2_a001 << "]"; outStrea02m002b << "[c2B1:" << doub_c2_b002 << "]" << endl; outStrea02m002b << "{欧氏距离:" << tmpEduclidDist01 << "}" << endl; SetPixe01d(hdc, c2Apianyi_A2 + c2_a001, c2Bpianyi_B2 + c2_b002, RGB(255, 200, 0)); //绿色 // }//if2100 else {//if2100else2100 SetPixe01d(hdc, c2Apianyi_A2 + c2_a001, c2Bpianyi_B2 + c2_b002, RGB(0, 200, 0)); //绿色 }//if2100else2100 }//for2100j2 //绘制大圆(或外圆) SetPixe01d(hdc, c1Apianyi_A1 + c1_a001, c1Bpianyi_B1 + c1_b001, RGB(200, 200, 0));// 228, 0));//黄 // }//for1100i1// //(阶段)结果: //再迭代: //[C1rad:2.07616]:{C1角度:118955}[坐标c1A1:2.06351e+06][c1B1:3.5e+06][C2rad2:2.8889] : {C2角度:165522][c2A1:2.06351e+06][c2B1:3.50002e+06]{ 欧氏距离:253.008 } //P1点:C1:61.045(角度) C2:14.478 //P2点:C1:118.955 C2:165.522 就是答案(相交点得角度 //验证: 90-61.045= ( 28.955)== 118.955-90=28.955 //同样验证: 90-14.478=(75.522)== 165.522-90=75.522 */ }//找交点P2代码块110 //找交点P2-End // // //开始发光、绘光-绘制光 370行 // // // int c2Bpianyi_B2 = 300;//小圆圆心位置-上下坐标 // int c2Apianyi_A2 = 400;//小圆圆心位置-左右坐标 int whichCircleNum = 2; long long lightLen = 99129;// 69;// 109;// 209;// 999; double angle001 = 0.0; // angle001 = (double)PIld* ((double)286.0 / 180);// 45.0 / 180); // angle001 = (double)PIld* ((double)257.0 / 180);// 45.0 / 180); angle001 = (double)PIld* ((double)98.0 / 180);// //light2Circle001参数: 0:HDC hdc; 1:int whichCircleNum先碰哪个圆 2:光线长度long long; 3:发光角度(如0~PIπ)为射向小圆2号圆;4:光源A坐标;5:光源B坐标) light2Circle001(hdc,whichCircleNum, lightLen, angle001, 410, 460); // //发光、绘光-End // return 1; }//int wm01paint01 //1100 // // 函数: 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(hWnd, ps, 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; } ```