001: /*
002: * $RCSfile: Basic.java,v $
003: *
004: * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * - Redistribution of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * - Redistribution in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * Neither the name of Sun Microsystems, Inc. or the names of
019: * contributors may be used to endorse or promote products derived
020: * from this software without specific prior written permission.
021: *
022: * This software is provided "AS IS," without a warranty of any
023: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026: * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027: * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028: * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029: * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030: * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031: * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032: * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033: * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034: * POSSIBILITY OF SUCH DAMAGES.
035: *
036: * You acknowledge that this software is not designed, licensed or
037: * intended for use in the design, construction, operation or
038: * maintenance of any nuclear facility.
039: *
040: * $Revision: 1.4 $
041: * $Date: 2007/02/09 17:20:17 $
042: * $State: Exp $
043: */
044:
045: // ----------------------------------------------------------------------
046: //
047: // The reference to Fast Industrial Strength Triangulation (FIST) code
048: // in this release by Sun Microsystems is related to Sun's rewrite of
049: // an early version of FIST. FIST was originally created by Martin
050: // Held and Joseph Mitchell at Stony Brook University and is
051: // incorporated by Sun under an agreement with The Research Foundation
052: // of SUNY (RFSUNY). The current version of FIST is available for
053: // commercial use under a license agreement with RFSUNY on behalf of
054: // the authors and Stony Brook University. Please contact the Office
055: // of Technology Licensing at Stony Brook, phone 631-632-9009, for
056: // licensing information.
057: //
058: // ----------------------------------------------------------------------
059: package com.sun.j3d.utils.geometry;
060:
061: import java.io.*;
062: import java.util.*;
063: import javax.vecmath.*;
064:
065: class Basic {
066:
067: static final double D_RND_MAX = 2147483647.0;
068:
069: static double detExp(double u_x, double u_y, double u_z,
070: double v_x, double v_y, double v_z, double w_x, double w_y,
071: double w_z) {
072:
073: return ((u_x) * ((v_y) * (w_z) - (v_z) * (w_y)) - (u_y)
074: * ((v_x) * (w_z) - (v_z) * (w_x)) + (u_z)
075: * ((v_x) * (w_y) - (v_y) * (w_x)));
076: }
077:
078: static double det3D(Tuple3f u, Tuple3f v, Tuple3f w) {
079: return ((u).x * ((v).y * (w).z - (v).z * (w).y) - (u).y
080: * ((v).x * (w).z - (v).z * (w).x) + (u).z
081: * ((v).x * (w).y - (v).y * (w).x));
082: }
083:
084: static double det2D(Tuple2f u, Tuple2f v, Tuple2f w) {
085: return (((u).x - (v).x) * ((v).y - (w).y) + ((v).y - (u).y)
086: * ((v).x - (w).x));
087: }
088:
089: static double length2(Tuple3f u) {
090: return (((u).x * (u).x) + ((u).y * (u).y) + ((u).z * (u).z));
091: }
092:
093: static double lengthL1(Tuple3f u) {
094: return (Math.abs((u).x) + Math.abs((u).y) + Math.abs((u).z));
095: }
096:
097: static double lengthL2(Tuple3f u) {
098: return Math.sqrt(((u).x * (u).x) + ((u).y * (u).y)
099: + ((u).z * (u).z));
100: }
101:
102: static double dotProduct(Tuple3f u, Tuple3f v) {
103: return (((u).x * (v).x) + ((u).y * (v).y) + ((u).z * (v).z));
104: }
105:
106: static double dotProduct2D(Tuple2f u, Tuple2f v) {
107: return (((u).x * (v).x) + ((u).y * (v).y));
108: }
109:
110: static void vectorProduct(Tuple3f p, Tuple3f q, Tuple3f r) {
111: (r).x = (p).y * (q).z - (q).y * (p).z;
112: (r).y = (q).x * (p).z - (p).x * (q).z;
113: (r).z = (p).x * (q).y - (q).x * (p).y;
114: }
115:
116: static void vectorAdd(Tuple3f p, Tuple3f q, Tuple3f r) {
117: (r).x = (p).x + (q).x;
118: (r).y = (p).y + (q).y;
119: (r).z = (p).z + (q).z;
120: }
121:
122: static void vectorSub(Tuple3f p, Tuple3f q, Tuple3f r) {
123: (r).x = (p).x - (q).x;
124: (r).y = (p).y - (q).y;
125: (r).z = (p).z - (q).z;
126: }
127:
128: static void vectorAdd2D(Tuple2f p, Tuple2f q, Tuple2f r) {
129: (r).x = (p).x + (q).x;
130: (r).y = (p).y + (q).y;
131: }
132:
133: static void vectorSub2D(Tuple2f p, Tuple2f q, Tuple2f r) {
134: (r).x = (p).x - (q).x;
135: (r).y = (p).y - (q).y;
136: }
137:
138: static void invertVector(Tuple3f p) {
139: (p).x = -(p).x;
140: (p).y = -(p).y;
141: (p).z = -(p).z;
142: }
143:
144: static void divScalar(double scalar, Tuple3f u) {
145: (u).x /= scalar;
146: (u).y /= scalar;
147: (u).z /= scalar;
148: }
149:
150: static void multScalar2D(double scalar, Tuple2f u) {
151: (u).x *= scalar;
152: (u).y *= scalar;
153: }
154:
155: static int signEps(double x, double eps) {
156: return ((x <= eps) ? ((x < -eps) ? -1 : 0) : 1);
157: }
158: }
|