001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.mlm.debug.ui.draw;
028:
029: /** Class MoreMath
030: *
031: * Provides functions that are not part of the standard Math class.
032: *
033: * Functions:
034: * asinh(float x) - hyperbolic arcsine
035: * sinh(float x) - hyperbolic sine
036: *
037: * Function Definition
038: * Hyperbolic sine (e^x-e^-x)/2
039: * Hyperbolic cosine (e^x+e^-x)/2
040: * Hyperbolic tangent (e^x-e^-x)/(e^x+e^-x)
041: * Hyperbolic arc sine log (x+sqrt(1+x^2))
042: * Hyperbolic arc cosine 2 log (sqrt((x+1)/2) + sqrt((x-1)/2))
043: * Hyperbolic arc tangent (log (1+x) - log (1-x))/2
044: *
045: *
046: * @since jdk1.1
047: * */
048:
049: public class MoreMath {
050: public static final float asinh(float x) {
051: return (float) Math.log(x + Math.sqrt(x * x + 1));
052: }
053:
054: public static final float sinh(float x) {
055: return (float) (Math.pow(Math.E, x) - Math.pow(Math.E, -x)) / 2.0f;
056: }
057:
058: /** roundAdjust() AKA qint() - return x s.t. it will be rounded
059: away from zero when we cast to an integer or long integer.
060: Please Note: This is FAST! */
061: public static final double roundAdjust(double in) {
062: return (((int) in) < 0) ? (in - 0.5) : (in + 0.5);
063: }
064:
065: public static final double qint(double x) {
066: return roundAdjust(x);
067: }
068:
069: /** lonDistance(lon1, lon2) - shortest arc distance btwn two lons */
070: public static final float lonDistance(float lon1, float lon2) {
071: return Math.min(Math.abs(lon1 - lon2), ((lon1 < 0) ? lon1 + 180
072: : 180 - lon1)
073: + ((lon2 < 0) ? lon2 + 180 : 180 - lon2));
074: }
075:
076: /** DEG_TO_SC() and SC_TO_DEG() - convert between decimal degrees
077: and scoords */
078: public static final long DEG_TO_SC(double deg) {
079: return (long) (deg * 3600000);
080: }
081:
082: public static final double SC_TO_DEG(int sc) {
083: return ((double) (sc) / (60.0 * 60.0 * 1000.0));
084: }
085:
086: // HACK - are there functions that already exist?
087: /** sign() - return sign of number */
088: public static final short sign(short x) {
089: return (x < 0) ? (short) -1 : (short) 1;
090: }
091:
092: public static final int sign(int x) {
093: return (x < 0) ? -1 : 1;
094: }
095:
096: public static final long sign(long x) {
097: return (x < 0) ? -1 : 1;
098: }
099:
100: public static final float sign(float x) {
101: return (x < 0f) ? -1 : 1;
102: }
103:
104: public static final double sign(double x) {
105: return (x < 0d) ? -1 : 1;
106: }
107: }
|