MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
laguerre_3updown.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file laguerre_3updown.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#laguerre-pole
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 Same as newton_3updown.cpp, but using Laguerre's method.
33*/
34/*******************************************************************************************************************************************************.H.E.**/
35/** @cond exj */
36
37//--------------------------------------------------------------------------------------------------------------------------------------------------------------
38#include "ramCanvas.hpp"
39
40//--------------------------------------------------------------------------------------------------------------------------------------------------------------
41int main(void) {
42 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
43 const int MAXITR = 255;
44 const int CCLMAG = 35;
45 const double ZMAGMX = 1e10;
46 const double YCENTR = 0.0;
47 const double ZROEPS = .0001;
48 const int IMGSIZ = 7680/1;
49 const double RELSIZ = 4.0; // 0.55; 14.5; 4.0; 0.15;
50 const double XCENTR = 0.5; // -4.7; 1.5; 0.5; -0.20;
51 const double r = 1.0; // 100.0; 100.0; 1.0; 0.001;
52 std::complex<double> r1( 1.0, 0.0);
53 std::complex<double> r2(-0.5, sin(2*std::numbers::pi/3));
54 std::complex<double> r3(-0.5, -sin(2*std::numbers::pi/3));
55 mjr::ramCanvas3c8b theRamCanvas(IMGSIZ, IMGSIZ, XCENTR-RELSIZ, XCENTR+RELSIZ, YCENTR-RELSIZ, YCENTR+RELSIZ);
56
57# pragma omp parallel for schedule(static,1)
58 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
59# pragma omp critical
60 if ((y%(IMGSIZ/100))==0)
61 std::cout << "line " << y << " of " << IMGSIZ << std::endl;
62 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
63 std::complex<double> z = theRamCanvas.int2real(x, y);
64 for(int count=0; count<MAXITR; count++) {
65 if(std::abs(z-r1) <= ZROEPS) {
66 theRamCanvas.drawPoint(x, y, mjr::ramCanvas3c8b::colorType::csCCu0R::c(count*CCLMAG)); break;
67 } else if(std::abs(z-r2) <= ZROEPS) {
68 theRamCanvas.drawPoint(x, y, mjr::ramCanvas3c8b::colorType::csCCu0G::c(count*CCLMAG)); break;
69 } else if(std::abs(z-r3) <= ZROEPS) {
70 theRamCanvas.drawPoint(x, y, mjr::ramCanvas3c8b::colorType::csCCu0B::c(count*CCLMAG)); break;
71 } else if(std::abs(z) <= ZROEPS) {
72 break;
73 } else if(std::abs(z) > ZMAGMX) {
74 break;
75 }
76 std::complex<double> G = 3.0 * z * z * (r + 1.0) / (pow(z, 3.0) - 1.0) / (pow(z, 3.0) + r);
77 std::complex<double> ABR = 6.0 * sqrt((r + 1.0) * (2.0 * pow(z, 6.0) - pow(z, 3.0) + r) * z /
78 pow(pow(z, 3.0) - 1.0, 2.0) / pow(pow(z, 3.0) + r, 2.0));
79 std::complex<double> ABP = G + ABR;
80 std::complex<double> ABN = G - ABR;
81 std::complex<double> AB = (std::abs(ABP) > std::abs(ABN) ? ABP : ABN);
82 z = z - 3.0 / AB;
83 }
84 }
85 }
86 theRamCanvas.writeTIFFfile("laguerre_3updown.tiff");
87 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
88 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
89}
90/** @endcond */
int main(int argc, char *argv[])