MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
newton_min_angle_starfish.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file newton_min_angle_starfish.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw a Newton Fractical@EOL
7 @std C++20
8 @copyright
9 @parblock
10 Copyright (c) 2024, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
11
12 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
13
14 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
15
16 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
18
19 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
20 without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 DAMAGE.
28 @endparblock
29 @filedetails
30
31 We do the standard Newton iterations, but we keep track of the minimum phase angle difference between the three bisectors between the roots. The distances
32 are used to set the r, g, b channels (i.e. distance to root 1/2 bisector is r, root 1/3 bisector is g, and root 2/3 bisector is b).
33
34 The standard Newton fractal is generated from @f$ f=z^2-1 @f$. This function is continuous on the entire complex plain. What do we get if we add poles in
35 imaginary axis mirror locations of the roots? i.e. for each root @f$ x+iy @f$ of @f$ f @f$, we add a pole at @f$ -x+iy @f$? The corresponding function is:
36 @f[ f=\frac{z^3-1}{z^3+1} @f]
37*/
38/*******************************************************************************************************************************************************.H.E.**/
39/** @cond exj */
40
41//--------------------------------------------------------------------------------------------------------------------------------------------------------------
42#include "ramCanvas.hpp"
43
44//--------------------------------------------------------------------------------------------------------------------------------------------------------------
45typedef mjr::ramCanvas3c8b rcT; // The Ram Canvas type we will use
46typedef rcT::colorChanType rcccT; // Color Channel Type
47
48//--------------------------------------------------------------------------------------------------------------------------------------------------------------
49int main(void) {
50 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
51 constexpr int MAXITR = 255;
52 constexpr double ZROEPS = .0001;
53 constexpr int IMGSIZ = 7680;
54 constexpr double ang1 = 0.0;
55 constexpr double ang2 = 2*std::numbers::pi/3;
56 constexpr double ang3 = -2*std::numbers::pi/3;
57 constexpr double ang12 = (ang1+ang2)/2.0;
58 constexpr double ang13 = (ang1+ang3)/2.0;
59 constexpr double ang23 = std::numbers::pi;
60 const double normer = std::log(2*std::numbers::pi/3);
61 const double r = 0.010;
62 std::complex<double> r1( 1.0, sin(ang1));
63 std::complex<double> r2(-0.5, sin(ang2));
64 std::complex<double> r3(-0.5, sin(ang3));
65 rcT theRamCanvas(IMGSIZ, IMGSIZ, -2.15/10.0, 1.85/10.0, -1.88/10.0, 1.89/10.0);
66
67# pragma omp parallel for schedule(static,1)
68 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
69 if ((y%100)==0)
70# pragma omp critical
71 std::cout << "line " << y << " of " << IMGSIZ << std::endl;
72 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
73 std::complex<double> z = theRamCanvas.int2real(x, y);
74 double minAngleDelta1 = std::numbers::pi;
75 double minAngleDelta2 = std::numbers::pi;
76 double minAngleDelta3 = std::numbers::pi;
77 for(int count=0; count<MAXITR; count++) {
78 double modz = std::abs(z);
79 if (modz<ZROEPS)
80 break;
81 z = (-pow(z, 0.6e1) + (0.2e1 * r + 0.4e1) * pow(z, 0.3e1) + r) * pow(z, -0.2e1) / (r + 0.1e1) / 0.3e1;
82 double curAngle = std::arg(z);
83 double curAngleDelta1 = std::abs(ang12-curAngle);
84 double curAngleDelta2 = std::abs(ang13-curAngle);
85 double curAngleDelta3 = std::min(std::abs(curAngle-ang23), std::abs(curAngle+ang23));
86 if(curAngleDelta1 < minAngleDelta1) minAngleDelta1 = curAngleDelta1;
87 if(curAngleDelta2 < minAngleDelta2) minAngleDelta2 = curAngleDelta2;
88 if(curAngleDelta3 < minAngleDelta3) minAngleDelta3 = curAngleDelta3;
89 if ((modz<ZROEPS) || (std::abs(z-r1)<ZROEPS) || (std::abs(z-r2)<ZROEPS) || (std::abs(z-r3)<ZROEPS))
90 break;
91 }
92 rcccT r = static_cast<rcccT>(50.0*std::log(minAngleDelta1)/normer);
93 rcccT g = static_cast<rcccT>(50.0*std::log(minAngleDelta2)/normer);
94 rcccT b = static_cast<rcccT>(50.0*std::log(minAngleDelta3)/normer);
95 theRamCanvas.drawPoint(x, y, rcT::colorType(r, g, b));
96 }
97 }
98
99 theRamCanvas.applyHomoPixTfrm(&rcT::colorType::tfrmPow, 0.4);
100 theRamCanvas.writeTIFFfile("newton_min_angle_starfish.tiff");
101 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
102 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
103}
104/** @endcond */
int main(int argc, char *argv[])