Java examples for java.lang:Math Value
calculates min of two values with smooth blending
/***************************************************************************** * 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; import static abfab3d.core.Output.fmt; public class Main{ /**/*from w ww. j ava 2 s. c o m*/ calculates min of two values with smooth blending */ public static final double blendMin(double a, double b, double w) { double dd = Math.min(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; } }