44#include "ramCanvas.hpp"
47typedef struct {
double x;
double y; } complex;
51const int MAXTRCNT = 250000;
52complex thePath[MAXTRCNT];
55int inSet(complex tstPt);
56int findAlphaTriangle(
int maxCnt,
int ptA,
int ptB,
double slop, complex triangle[3]);
57int traceBoundry(
int maxCnt,
double epsilon,
int goOtherWay, complex alphaTriangle[3], complex thePath[],
int *pathLen);
58int orbCmp(complex tstPt);
62 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
71 complex protoAlphaTriangle[3] = { {0.0, 0.0}, {0.001, 0.0}, {0.0001, 0.001} };
73 mjr::ramCanvas3c8b theRamCanvas(7680/4, 7680/4, -2.1, 1.1, -1.5, 1.5);
78 std::cout <<
"INFO(main): Draw reference set via fill algorithm." << std::endl;
79 for(
int yy=0;yy<theRamCanvas.getNumPixY();yy++) {
80 for(
int xx=0;xx<theRamCanvas.getNumPixX();xx++) {
82 tpt.x = theRamCanvas.int2realX(xx);
83 tpt.y = theRamCanvas.int2realY(yy);
84 int clr = orbCmp(tpt);
85 theRamCanvas.drawPoint(xx, yy, mjr::ramCanvas3c8b::colorType::csPGrey3x::c(
static_cast<mjr::ramCanvas3c8b::csIntType
>((100*clr)%768)));
91 for(MAXCOUNT = 1; MAXCOUNT < 10; MAXCOUNT++) {
92 std::cout <<
"INFO(main): Curve: " << MAXCOUNT << std::endl;
94 complex alphaTriangle[3];
95 for(
int i=0; i<3; i++)
96 alphaTriangle[i] = protoAlphaTriangle[i];
97 if(findAlphaTriangle(MAXTRCNT, 0, 1, 0.0, alphaTriangle)) {
99 traceBoundry(MAXTRCNT, 0.00003, 0, alphaTriangle, thePath, &thePathLen);
100 theRamCanvas.drawPLCurve(thePathLen+1, (mjr::ramCanvas3c8b::pointFltType *)thePath, mjr::ramCanvas3c8b::colorType(255, 0, 255));
104 theRamCanvas.writeTIFFfile(
"mandelbrot_triangle.tiff");
105 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
106 std::cout <<
"Total Runtime " << runTime.count() <<
" sec" << std::endl;
110int orbCmp(complex tstPt) {
111 mjr::ramCanvas3c8b::coordFltType zx = 0.0;
112 mjr::ramCanvas3c8b::coordFltType zy = 0.0;
114 mjr::ramCanvas3c8b::coordFltType tempx;
116 if(zx * zx + zy * zy >= 4)
120 tempx = zx * zx - zy * zy + tstPt.x;
121 zy = 2 * zx * zy + tstPt.y;
128int inSet(complex tstPt) {
137int findAlphaTriangle(
int maxCnt,
int ptA,
int ptB,
double slop, complex triangle[3]) {
141 mjr::ramCanvas3c8b::coordFltType xDelta = triangle[ptB].x - triangle[ptA].x;
142 mjr::ramCanvas3c8b::coordFltType yDelta = triangle[ptB].y - triangle[ptA].y;
145 xDelta = (xDelta - xDelta * slop);
146 yDelta = (yDelta - yDelta * slop);
150 hitCount = inSet(triangle[0])+inSet(triangle[1])+inSet(triangle[2]);
151 if( (hitCount >= 1) && (hitCount <= 2) ) {
153 std::cerr <<
"INFO(findAlphaTriangle): Found alpha triangle!" << std::endl;
157 for(
int i=0; i<3; i++) {
158 triangle[i].x = triangle[i].x + xDelta;
159 triangle[i].y = triangle[i].y + yDelta;
165 std::cerr <<
"ERROR(findAlphaTriangle): Too many iterations!" << std::endl;
191int traceBoundry(
int maxCnt,
double epsilon,
int goOtherWay, complex alphaTriangle[3], complex thePath[],
int *pathLen) {
192 complex curTriangle[3];
194 int pInState[3], pInStateSum;
195 int insIdx, unkIdx, outIdx, tmpIdx;
198 for(
int i=0; i<3; i++) {
199 curTriangle[i] = alphaTriangle[i];
200 pInState[i] = inSet(curTriangle[i]);
206 for(
int i=0; i<3; i++)
207 pInStateSum += pInState[i];
208 if(pInStateSum >= 3) {
210 std::cerr <<
"ERROR(traceBoundry): All vertexes of alpha triangle in set!" << std::endl;
213 if(pInStateSum <= 0) {
215 std::cerr <<
"ERROR(traceBoundry): No vertexes of alpha triangle in set!" << std::endl;
220 insIdx = unkIdx = outIdx = -1;
221 for(
int i=0; i<3; i++) {
239 std::cerr <<
"WARNING(traceBoundry): goOtherWay is ineffective in this case!" << std::endl;
249 thePath[*pathLen].x = (curTriangle[insIdx].x + curTriangle[outIdx].x)/2;
250 thePath[*pathLen].y = (curTriangle[insIdx].y + curTriangle[outIdx].y)/2;
253 for(
int count=0;(count<(maxCnt-1))||(maxCnt==0);count++) {
255 curTriangle[unkIdx].x = curTriangle[insIdx].x + curTriangle[outIdx].x - curTriangle[unkIdx].x;
256 curTriangle[unkIdx].y = curTriangle[insIdx].y + curTriangle[outIdx].y - curTriangle[unkIdx].y;
259 if(inSet(curTriangle[unkIdx])) {
271 thePath[*pathLen].x = (curTriangle[insIdx].x + curTriangle[outIdx].x)/2;
272 thePath[*pathLen].y = (curTriangle[insIdx].y + curTriangle[outIdx].y)/2;
275 if( (fabs(thePath[*pathLen].x - thePath[0].x) + fabs(thePath[*pathLen].y - thePath[0].y)) < epsilon) {
277 std::cerr <<
"INFO(traceBoundry): Came back upon self (itr: " << count <<
"). Done." << std::endl;
283 std::cerr <<
"INFO(traceBoundry): Max iteration count reached. Done." << std::endl;
int main(int argc, char *argv[])