calculates max of two values with smooth blending - Java java.lang

Java examples for java.lang:Math Value

Description

calculates max of two values with smooth blending

Demo Code

/*****************************************************************************
 *                        Shapeways, Inc Copyright (c) 2011
 *                               Java Source
 *
 * This source is licensed under the GNU LGPL v2.1
 * Please read http://www.gnu.org/copyleft/lgpl.html for more information
 *
 * This software comes with the standard NO WARRANTY disclaimer for any
 * purpose. Use it at your own risk. If there's a problem you get to fix it.
 *
 ****************************************************************************/
import javax.vecmath.Vector3d;
import javax.vecmath.Vector4d;
import javax.vecmath.AxisAngle4d;
import javax.vecmath.Quat4d;
import javax.vecmath.Matrix3d;
import javax.vecmath.SingularMatrixException;
import static java.lang.Math.sqrt;
import static java.lang.Math.abs;
import static java.lang.Math.max;

public class Main{
    /**//from   w w w .  jav  a 2  s.  c  o  m
       calculates max of two values with smooth blending 
     */
    public static final double blendMax(double a, double b, double w) {

        double dd = Math.max(a, b);
        if (w <= 0.)
            return dd;
        double d = Math.abs(a - b);
        if (d < w)
            return dd + w * blendQuadric(d / w);
        else
            return dd;
    }
    /**
       quadratic blending function to be used in blendMin and blendMax
     */
    public static final double blendQuadric(double x) {
        return (1. - x) * (1. - x) * 0.25;
    }
}

Related Tutorials