🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
一、 总有一些图形会出乎意料: 参数为: 1、 //输入初始参数: double arc1 = (-5.0 / 16.0)*Pild;// //hdc:画板,arc1入射角-Pi~~+Pi,3线段次数,x=400,y=310为起始点! light01line03(hdc, arc1, 3, 400, 310);// 如: ![](https://box.kancloud.cn/0906ba6f80e4a385b266db4b8c5ae0f7_884x729.png) 2、 rc1 = (-7.0 / 16.0)*Pild;// //hdc:画板,arc1入射角-Pi~~+Pi,3线段次数,x=400,y=310为起始点! light01line03(hdc, arc1, 3, 400, 310);// ![](https://box.kancloud.cn/3ebe4a6a47221a0d1b8d2d9ef9cdff6d_560x519.png) 核心代码: ``` //hdc绘图板, arc1arg01入射角 linelength线长,x0初始点坐标X,y0:Y初始 int light01line03(HDC hdc, double arc1arg01, unsigned long linelength, double x0, double y0) { double arc1arg02; arc1arg02 = regularAngle(arc1arg01); double X001 = x0; double Y001 = y0; line2normal(hdc, arc1arg01, X001, Y001, RGB(0, 200, 200),10); cout << "[arc1arg01:" << arc1arg01 << "]-"; cout << "[arc1arg02:" << arc1arg02 << "]; "; unsigned long itime = 0; // int laiguoTimes = 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 { label01star01begin01: if (linelength < 1) { return 1; } lable110: //++itime; itime = 1; cout << "[itime:" << itime << "]_"; lable220: //开始算 反射角,并 (继续)光进 Xorigin01 = cos(arc1arg02)*(double)itime; Yorigin01 = sin(arc1arg02)*(double)itime; lable230: X001 = Xorigin01 + old1X001; Y001 = Yorigin01 + old1Y001; cou02t << "[X001:" << X001 << "]-"; cou02t << "[Y001:" << Y001 << "];"<<endl; setpixe02l(hdc, X001, Y001, RGB(255, 25, 0));// , 255, 0));//封装,封装都是有目的 的;没有目的 的“瞎封装”…会从我的小组被开除. //下面进入判断是否该反射,咋反射(和哪个圆反射…! lable330: //判断点的状态 // if (isInC1Bigcircle(X001, Y001) && (isInC2littlecircle(X001, Y001)) //if110 此点(新旧点)都在两圆内 if(1==isInTwoCircles(X001,Y001) ) // { setpixe02l(hdc, X001, Y001, RGB(255, 0, 0));// cou02t << "[01itime:" << itime << "]_"; old1X001 = X001; old1Y001 = Y001; // ++itime; itime = 1; goto lable220; }//if110 //与小圆相交-下面的:old点在 小圆(两圆)内,而新点 在 小圆(c2)外(但在大圆内--即与小圆的(下弧)相交呗 else if ( isInTwoCircles(old1X001,old1Y001) && (isInC1Bigcircle(X001, Y001) && (!isInC2littlecircle(X001, Y001)) ) ) //if110elseif110 { arc01normal01origin001 = atan((400 - X001) / (Y001 - 400)); if (0 == arc01normal01origin001) { // arc01normal01origin001 = 0.00001; cou04t << "[2小圆外itim01e:" << itime << "]__"; itime = 1; } arc1normal01 = Pild / 2.0 + arc01normal01origin001; line2normal(hdc, arc1normal01, old1X001, old1Y001, RGB(0, 0, 100), 4);// 60);//蓝 法线 fanshe01Arc01 = arc1arg02 - 2 * arc1normal01; reflecteAng01 = Pild- fanshe01Arc01; line2normal(hdc, reflecteAng01, old1X001, old1Y001, RGB(0, 200, 0), 6);// 90);//绿试画反射线 0, 0, 200)); arc1arg02 = reflecteAng01; cou04t << "[2小圆外itim2e:" << itime << "]_"; itime = 1; //这时回去,不用新点X001..!用old1X001等 line2normal(hdc, arc1normal01, old1X001, old1Y001, RGB(0,0,200)); goto lable220; }//if110elseif110 //与大圆相交//下面的:old点在 两圆(大圆、小圆)内,而新点 跑在 大圆外(但在小圆内--即与大圆(C1)相交 else if (isInTwoCircles(old1X001,old1Y001) && ( !isInC1Bigcircle(X001,Y001)&& (isInC2littlecircle(X001,Y001) ) ) )//if110elseif120 { arc01normal01origin001 = atan((400 - X001) / (Y001 - 0)); arc1normal01 = -(Pild / 2.0 - arc01normal01origin001); line2normal(hdc, arc1normal01, old1X001, old1Y001, RGB(0, 0, 255), 9);//蓝 法线 fanshe01Arc01 = Pild + arc1arg02 - 2 * arc1normal01; reflecteAng01 = - fanshe01Arc01; arc1arg02 = reflecteAng01; line2normal(hdc, reflecteAng01, old1X001, old1Y001, RGB(255, 200, 0), 5);//黄试画反射线 0, 0, 200)); line2normal(hdc, reflecteAng01, X001, Y001, RGB(0, 200, 0), 10);//绿试画反射线 0, 0, 200)); cou04t << "[itime:" << itime << "]_"; cou04t << "[跑到大圆外itime:" << itime << "]__"; itime = 1; //这时回去,不用新点X001,Y001 ++itime; // old1X001 = X001; old1Y001 = Y001; // X001 = old1X001; Y001 = old1Y001; goto lable220; }//if110elseif120 //Old点(还)在两圆内, (而)新点X001,Y001在两圆外了 else if ( isInTwoCircles(old1X001,old1Y001) &&( !isInC1Bigcircle(X001, Y001) && !(isInC2littlecircle(X001, Y001) ) ) )//if110elseif130 { lable450: //迭代找交点(找有 1圆相交了) mid01X01 = (X001 + old1X001) / 2; mid01Y01 = (X001 + old1Y001) / 2; if (isInTwoCircles(mid01X01, mid01Y01)) { old1X001 = mid01X01; old1Y001 = mid01Y01; cout << "[old1X001:" << old1X001 << "]-"; cout << "[old1Y001:" << old1Y001 << "]; "; cout << "[X001:" << X001 << "]-"; cout << "[Y001:" << Y001 << "]; "; cout << "[mid01X01:" << mid01X01 << "]-"; cout << "[mid01Y01:" << mid01Y01 << "]; "; goto lable450; }//if550 else { //此时:mid 点 (都)在 两圆外了? X001 = mid01X01; //退回半(中间点) Y001 = mid01Y01; goto lable330; //总之,要 一脚old在两圆内,而一脚(X001,Y001)在单圆外,发生反射,才跳出 lable330到本段 程序。 }//if550else560 //迭代找交点(哪个圆 先相交) }//if110elseif130 else ////if110else240 { mid01X01 = (X001 + old1X001) / 2; mid01Y01 = (X001 + old1Y001) / 2; goto lable330; }//if110else240 lable420: old1X001 = X001; old1Y001 = Y001; if (itime <= linelength) { goto lable110; } // } while (true);//循环光走(光线前进)并反射等 }//int light01line03(HDC hdc, double arc1arg01, unsigned long linelength, double x0, double y0 // ```