1 /**
2 * Mandelbulber v2, a 3D fractal generator _%}}i*<. ______
3 * Copyright (C) 2020 Mandelbulber Team _>]|=||i=i<, / ____/ __ __
4 * \><||i|=>>%) / / __/ /___/ /_
5 * This file is part of Mandelbulber. )<=i=]=|=i<> / /__ /_ __/_ __/
6 * The project is licensed under GPLv3, -<>>=|><|||` \____/ /_/ /_/
7 * see also COPYING file in this folder. ~+{i%+++
8 *
9 * menger poly fold
10 * @reference
11 * https://fractalforums.org/fragmentarium/17/polyfoldsym-pre-transform/2684
12 */
13
14 #include "all_fractal_definitions.h"
15
cFractalMengerPolyFold()16 cFractalMengerPolyFold::cFractalMengerPolyFold() : cAbstractFractal()
17 {
18 nameInComboBox = "Menger - Poly Fold";
19 internalName = "menger_poly_fold";
20 internalID = fractal::mengerPolyFold;
21 DEType = analyticDEType;
22 DEFunctionType = linearDEFunction;
23 cpixelAddition = cpixelDisabledByDefault;
24 defaultBailout = 10.0;
25 DEAnalyticFunction = analyticFunctionIFS;
26 coloringFunction = coloringFunctionIFS;
27 }
28
FormulaCode(CVector4 & z,const sFractal * fractal,sExtendedAux & aux)29 void cFractalMengerPolyFold::FormulaCode(CVector4 &z, const sFractal *fractal, sExtendedAux &aux)
30 {
31 CVector4 oldZ = z;
32 if (aux.i >= fractal->transformCommon.startIterations
33 && aux.i < fractal->transformCommon.stopIterations1)
34 {
35 // pre abs
36 if (fractal->transformCommon.functionEnabledx) z.x = fabs(z.x);
37 if (fractal->transformCommon.functionEnabledyFalse) z.y = fabs(z.y);
38 if (fractal->transformCommon.functionEnabledzFalse) z.z = fabs(z.z);
39
40 if (fractal->transformCommon.functionEnabledCx)
41 {
42 if (fractal->transformCommon.functionEnabledAxFalse && z.y < 0.0) z.x = -z.x;
43 double psi = M_PI / fractal->transformCommon.int8X;
44 psi = fabs(fmod(atan(z.y / z.x) + psi, 2.0 * psi) - psi);
45 double len = sqrt(z.x * z.x + z.y * z.y);
46 z.x = cos(psi) * len;
47 z.y = sin(psi) * len;
48 }
49
50 if (fractal->transformCommon.functionEnabledCyFalse)
51 {
52 if (fractal->transformCommon.functionEnabledAyFalse && z.z < 0.0) z.y = -z.y;
53 double psi = M_PI / fractal->transformCommon.int8Y;
54 psi = fabs(fmod(atan(z.z / z.y) + psi, 2.0 * psi) - psi);
55 double len = sqrt(z.y * z.y + z.z * z.z);
56 z.y = cos(psi) * len;
57 z.z = sin(psi) * len;
58 }
59
60 if (fractal->transformCommon.functionEnabledCzFalse)
61 {
62 if (fractal->transformCommon.functionEnabledAzFalse && z.x < 0.0) z.z = -z.z;
63 double psi = M_PI / fractal->transformCommon.int8Z;
64 psi = fabs(fmod(atan(z.x / z.z) + psi, 2.0 * psi) - psi);
65 double len = sqrt(z.z * z.z + z.x * z.x);
66 z.z = cos(psi) * len;
67 z.x = sin(psi) * len;
68 }
69
70 z += fractal->transformCommon.additionConstant000;
71
72 // rotation
73 if (fractal->transformCommon.rotation2EnabledFalse)
74 {
75 z = fractal->transformCommon.rotationMatrix.RotateVector(z);
76 }
77 }
78
79 // Menger Sponge
80 z = fabs(z);
81 if (z.x - z.y < 0.0) swap(z.y, z.x);
82 if (z.x - z.z < 0.0) swap(z.z, z.x);
83 if (z.y - z.z < 0.0) swap(z.z, z.y);
84 z *= fractal->transformCommon.scale3;
85 z.x -= 2.0 * fractal->transformCommon.constantMultiplierA111.x;
86 z.y -= 2.0 * fractal->transformCommon.constantMultiplierA111.y;
87 if (z.z > 1.0) z.z -= 2.0 * fractal->transformCommon.constantMultiplierA111.z;
88 aux.DE *= fabs(fractal->transformCommon.scale3 * fractal->transformCommon.scaleA1);
89
90 z += fractal->transformCommon.additionConstantA000;
91
92 if (fractal->analyticDE.enabled)
93 {
94 if (!fractal->analyticDE.enabledFalse)
95 aux.DE = aux.DE * fractal->analyticDE.scale1 + fractal->analyticDE.offset0;
96 else
97 {
98 double avgScale = z.Length() / oldZ.Length();
99 aux.DE = aux.DE * avgScale * fractal->analyticDE.scale1 + fractal->analyticDE.offset0;
100 }
101 }
102 }
103