```
// 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;
}
```
- vs2017宇宙最偉大IDE用Console等調試匯總
- c++Win32起始鼠標作圖181101
- 用迭代法找(兩圓的)交點-精確計算迭代并改進-數值周期1810
- 精度-比例關系181110P2點
- 用迭代法求找兩圓交點-精度計算181111A
- 月亮型-大小圓-上下圓算法181121
- 用c++的數學計算及圖形繪制總結之1/共4-181101
- 用c++做數學計算及圖形繪制總結之2/4-181102
- 用c++做數學計算及圖形繪制總結之3/4-181103
- 用c++做數學計算及圖形繪制總結4/4-181104
- 用c++的移位代替乘除運算181105
- 重構billiard2圓相交-非遞歸181101-非預料內圖形-原因分析181201
- 重構月亮型billiard202圓相交-非遞歸181102-非預料內圖形-原因分析181202
- 重構月亮型billiard202圓相交-非遞歸181102b-非預料內圖形-原因分析181202b
- 單橢圓(非遞歸)18圣誕后-ok版181225