MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
newton_roter.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_roter.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Simplified code for Newton's Fractical.@EOL
7 @std C++20
8 @see https://www.mitchr.me/SS/newton/index.html#roter
9 @copyright
10 @parblock
11 Copyright (c) 1988-2022, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
14
15 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19
20 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
21 without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 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
28 DAMAGE.
29 @endparblock
30 @filedetails
31
32 Newton's method on (z^6-1)/(a^6*z^6+b). The bottom specifies a set of 6 poles on a circle of radius b and centered at the origin. The a variable is
33 a modulus one complex number used to spin the poles around the circle like they orbit the origin.
34
35 time convert -delay 1 -loop 0 -dispose previous newton_roter_???.tiff newton_roter.gif
36
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
46
47//--------------------------------------------------------------------------------------------------------------------------------------------------------------
48int main(void) {
49 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
50 const int MAXITR = 255;
51 const int CCLMAG = 130;
52 const int DCLMAG = 30;
53 const int NUMFRM = 4*8;
54 const double ZMAGMX = 1e10;
55 const double RELSIZ = 7.0;
56 const double XCENTR = 0.0;
57 const double YCENTR = 0.0;
58 const double ZROEPS = .0001;
59 const int IMGSIZ = 7680/16;
60 const std::complex<double> r1( 1.0, 0.0);
61 const std::complex<double> r2(-0.5, std::sin(2*std::numbers::pi/3));
62 const std::complex<double> r3(-0.5, -std::sin(2*std::numbers::pi/3));
63
64# pragma omp parallel for schedule(static,1)
65 for(int frame=0; frame<NUMFRM; frame++) {
66# pragma omp critical
67 std::cout << "frame " << (frame+1) << " of " << NUMFRM << std::endl;
68 rcT theRamCanvas(IMGSIZ, IMGSIZ, XCENTR-RELSIZ, XCENTR+RELSIZ, YCENTR-RELSIZ, YCENTR+RELSIZ);
69 double angle = 2.0*std::numbers::pi/6.0/NUMFRM*frame;
70 std::complex<double> a(std::cos(angle), std::sin(angle));
71 double b = 1e-2;
72 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
73 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
74 std::complex<double> z = theRamCanvas.int2real(x, y);
75 std::complex<double> zL = z + 100.0;
76 for(int count=0; count<MAXITR; count++) {
77 if(std::abs(z-zL) <= ZROEPS) {
78 theRamCanvas.drawPoint(x, y, rcT::colorType::csCCu0R::c(count*CCLMAG)); break;
79 } else if(std::abs(z) <= ZROEPS) {
80 break;
81 } else if(std::abs(z) > ZMAGMX) {
82 theRamCanvas.drawPoint(x, y, rcT::colorType::csCCu0W::c(count*DCLMAG)); break;
83 break;
84 }
85 zL = z;
86 if (b<1e11)
87 z = (-pow(a, 6.0) * pow(z, 12.0) + (7.0 * pow(a, 6.0) + (5.0 * b)) * pow(z, 6.0) + b) /
88 pow(z, 5.0) / (pow(a, 6.0) + b) / 6.0;
89 else
90 z = (5.0 * pow(z, 6.0) + 1.0) / pow(z, 5.0) / 6.0;
91 }
92 }
93 }
94 theRamCanvas.writeTIFFfile("newton_roter_" + mjr::math::str::fmt_int(frame, 3, '0') + ".tiff");
95 }
96 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
97 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
98}
99/** @endcond */
int main(int argc, char *argv[])