Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- JWildfire - an image and animation processor written in Java
- Copyright (C) 1995-2011 Andreas Maschke
- This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
- General Public License as published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
- This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License along with this software;
- if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
- package org.jwildfire.create.tina.variation;
- import static org.jwildfire.base.mathlib.MathLib.sqrt;
- import static org.jwildfire.base.mathlib.MathLib.min;
- import static org.jwildfire.base.mathlib.MathLib.max;
- import static org.jwildfire.base.mathlib.MathLib.asin;
- import org.jwildfire.create.tina.base.XForm;
- import org.jwildfire.create.tina.base.XYZPoint;
- public class EllipticAltFunc extends SimpleVariationFunc {
- private static final long serialVersionUID = 1L;
- private double sqrt1pm1(double x) {
- if (-0.0625 < x && x < 0.0625)
- {
- // [4,4] Pade approximant to degree 8 truncated Taylor series of sqrt(x+1)-1 about 0
- // computed with a Wolfram Alpha Open Code notebook
- // accurate to machine precision within this range?
- double num = 0;
- double den = 0;
- num += 1.0 / 32.0;
- den += 1.0 / 256.0;
- num *= x;
- den *= x;
- num += 5.0 / 16.0;
- den += 5.0 / 32.0;
- num *= x;
- den *= x;
- num += 3.0 / 4.0;
- den += 15.0 / 16.0;
- num *= x;
- den *= x;
- num += 1.0 / 2.0;
- den += 7.0 / 4.0;
- num *= x;
- den *= x;
- den += 1.0;
- return num / den;
- }
- return sqrt(1 + x) - 1;
- }
- @Override
- public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
- /* Alternate elliptic implementation by claude on discord fractal chat.
- * It has better precision when x is near ±1 and y is near 0.
- */
- double x2 = 2.0 * pAffineTP.x;
- double sq = pAffineTP.x * pAffineTP.x + pAffineTP.y * pAffineTP.y;
- double u = sq + x2;
- double v = sq - x2;
- double xmaxm1 = 0.5 * (sqrt1pm1(u) + sqrt1pm1(v));
- double a = pAffineTP.x / (1 + xmaxm1);
- double ssx = xmaxm1;
- double w = pAmount / 1.5707963267948966;
- if (ssx<0) ssx = 0; else ssx = sqrt(ssx);
- pVarTP.x = w * asin(max(-1, min(1, a))); //asin(clamp(a, -1, 1));
- if (pAffineTP.y > 0)
- pVarTP.y = w * Math.log1p(xmaxm1 + ssx);
- else
- pVarTP.y = -w * Math.log1p(xmaxm1 + ssx);
- if (pContext.isPreserveZCoordinate()) pVarTP.z += pAmount * pAffineTP.z;
- }
- @Override
- public String getName() {
- return "ellipticAlt";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement