├── .gitignore ├── src └── javax │ └── vecmath │ ├── package-info.java │ ├── VecMathI18N.java │ ├── SingularMatrixException.java │ ├── MismatchedSizeException.java │ ├── VecMathUtil.java │ ├── Point2i.java │ ├── Point3i.java │ ├── Point4i.java │ ├── TexCoord2f.java │ ├── TexCoord3f.java │ ├── TexCoord4f.java │ ├── Point2d.java │ ├── Point2f.java │ ├── Color3b.java │ ├── ExceptionStrings.properties │ ├── Color3f.java │ ├── Color4b.java │ ├── Color4f.java │ ├── Vector2f.java │ ├── Vector2d.java │ ├── Point3d.java │ ├── Point3f.java │ ├── Vector3d.java │ ├── Vector3f.java │ ├── Vector4f.java │ ├── Vector4d.java │ ├── Point4f.java │ ├── Point4d.java │ ├── Tuple3b.java │ ├── Tuple4b.java │ ├── Tuple2i.java │ ├── Tuple3i.java │ ├── Tuple2d.java │ └── Tuple2f.java ├── README-FIRST.txt ├── LICENSE-SPEC.html ├── docs ├── api-changes-1_6.txt ├── api-changes-1_4.txt └── api-changes-1_5.txt ├── README-build.html └── COPYRIGHT.txt /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | -------------------------------------------------------------------------------- /src/javax/vecmath/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides 3D vector mathematics classes. 3 | */ 4 | package javax.vecmath; 5 | -------------------------------------------------------------------------------- /README-FIRST.txt: -------------------------------------------------------------------------------- 1 | The source code for the vecmath project is copyrighted code 2 | that is licensed to individuals or companies who download or otherwise 3 | access the code. 4 | 5 | The copyright notice for this project is in COPYRIGHT.txt 6 | 7 | The source code license information for this project is in LICENSE.txt 8 | 9 | Instructions for building this project are in README-build.html 10 | 11 | Note that the source code in this directory is untested and presumed 12 | incompatible with the Java 3D(TM) API specification. You must only use 13 | this code in accordance with the terms under which the code is 14 | licensed. No additional rights are granted to you. 15 | 16 | If you prefer to use a tested and certified compatible version of the 17 | code, then you can download a binary release for the Solaris, Linux, 18 | Windows, and Mac OS X operating environments at: 19 | https://java3d.dev.java.net/binary-builds.html 20 | or at: 21 | http://java.sun.com/products/java-media/3D/ 22 | -------------------------------------------------------------------------------- /LICENSE-SPEC.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 6 |Copyright 1996-2008 Sun Microsystems, Inc. All rights reserved. 10 | Use is subject to license terms. 11 |
12 |This javadoc-generated API documentation is not an 13 | official API specification. This documentation may contain references to 14 | Java and Java 3D, both of which are trademarks of Sun Microsystems, Inc. 15 | Any reference to these and other trademarks of Sun Microsystems are 16 | for explanatory purposes only. Their use does impart any rights beyond 17 | those listed in the source code license. In particular, Sun Microsystems 18 | retains all intellectual property and trademark rights as described in 19 | the proprietary rights notice in the COPYRIGHT.txt file. 20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /docs/api-changes-1_6.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | $RCSfile$ 3 | $Revision$ 4 | $Date$ 5 | ------------------------------------------------------------------------ 6 | This document conatains proposed API changes to the vecmath 1.6 API 7 | that deviate from the 1.5 API. 8 | 9 | This file must be updated to record the addition or deprecation of any 10 | public or protected class, interface, field, constructor, or method to 11 | the vecmath API. 12 | 13 | The one exception to this rule is that you don't need to update this 14 | file when adding a non-final (i.e., virtual) method to a class if that 15 | method--with exactly the same signature--already exists in a 16 | superclass. For example, adding a "toString" method to a vecmath object 17 | doesn't require an entry in this file. 18 | 19 | No incompatible changes to the vecmath 1.5 API are allowed. 20 | 21 | 22 | I. New/deprecated fields, constructors, methods 23 | 24 |To
25 | build the vecmath package, you must first checkout the vecmath
27 | svn
28 | repository on java.net. For example, run
29 | the svn checkout command as follows:
30 |
cd <j3d-root-dir>svn checkout https://vecmath.dev.java.net/svn/vecmath/branches/dev-1_6 vecmath
34 | This top-level directory must be named "vecmath". 37 |
38 |Vecmath is 100% Java, so any operating environment that supports
41 | J2SE should work. We have built vecmath on the following
42 | operating environments:
43 |
The following software must be installed:
52 |Before you start building, 65 | please check that your PATH must 66 | include the 67 | following directories:
68 |The default target, jar-opt, creates an optimized jar files.
73 |
Steps: 75 |
76 | cd <j3d-root-dir>/vecmath
78 | ant
79 | This will build the javax.vecmath package, which will
81 | be put
82 | in the vecmath/build/opt sub-directory.
83 |
To see other targets that are available, type "ant 85 | -projecthelp". Note that ant must be run from the top-level 86 | directory.
87 | 88 | 89 | -------------------------------------------------------------------------------- /src/javax/vecmath/TexCoord3f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 3 element texture coordinate that is represented by single precision 32 | * floating point x,y,z coordinates. 33 | * 34 | */ 35 | public class TexCoord3f extends Tuple3f implements java.io.Serializable { 36 | 37 | // Combatible with 1.1 38 | static final long serialVersionUID = -3517736544731446513L; 39 | 40 | /** 41 | * Constructs and initializes a TexCoord3f from the specified xyz 42 | * coordinates. 43 | * @param x the x coordinate 44 | * @param y the y coordinate 45 | * @param z the z coordinate 46 | */ 47 | public TexCoord3f(float x, float y, float z) 48 | { 49 | super(x,y,z); 50 | } 51 | 52 | 53 | /** 54 | * Constructs and initializes a TexCoord3f from the array of length 3. 55 | * @param v the array of length 3 containing xyz in order 56 | */ 57 | public TexCoord3f(float[] v) 58 | { 59 | super(v); 60 | } 61 | 62 | 63 | /** 64 | * Constructs and initializes a TexCoord3f from the specified TexCoord3f. 65 | * @param v1 the TexCoord3f containing the initialization x y z data 66 | */ 67 | public TexCoord3f(TexCoord3f v1) 68 | { 69 | super(v1); 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a TexCoord3f from the specified Tuple3f. 75 | * @param t1 the Tuple3f containing the initialization x y z data 76 | */ 77 | public TexCoord3f(Tuple3f t1) 78 | { 79 | super(t1); 80 | } 81 | 82 | 83 | /** 84 | * Constructs and initializes a TexCoord3f from the specified Tuple3d. 85 | * @param t1 the Tuple3d containing the initialization x y z data 86 | */ 87 | public TexCoord3f(Tuple3d t1) 88 | { 89 | super(t1); 90 | } 91 | 92 | 93 | /** 94 | * Constructs and initializes a TexCoord3f to (0,0,0). 95 | */ 96 | public TexCoord3f() 97 | { 98 | super(); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/javax/vecmath/TexCoord4f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 4 element texture coordinate that is represented by single precision 32 | * floating point x,y,z,w coordinates. 33 | * 34 | * @since vecmath 1.3 35 | */ 36 | public class TexCoord4f extends Tuple4f implements java.io.Serializable { 37 | 38 | // Combatible with 1.1 39 | static final long serialVersionUID = -3517736544731446513L; 40 | 41 | /** 42 | * Constructs and initializes a TexCoord4f from the specified xyzw 43 | * coordinates. 44 | * @param x the x coordinate 45 | * @param y the y coordinate 46 | * @param z the z coordinate 47 | * @param w the w coordinate 48 | */ 49 | public TexCoord4f(float x, float y, float z, float w) 50 | { 51 | super(x,y,z,w); 52 | } 53 | 54 | 55 | /** 56 | * Constructs and initializes a TexCoord4f from the array of length 4. 57 | * @param v the array of length w containing xyzw in order 58 | */ 59 | public TexCoord4f(float[] v) 60 | { 61 | super(v); 62 | } 63 | 64 | 65 | /** 66 | * Constructs and initializes a TexCoord4f from the specified TexCoord4f. 67 | * @param v1 the TexCoord4f containing the initialization x y z w data 68 | */ 69 | public TexCoord4f(TexCoord4f v1) 70 | { 71 | super(v1); 72 | } 73 | 74 | 75 | /** 76 | * Constructs and initializes a TexCoord4f from the specified Tuple4f. 77 | * @param t1 the Tuple4f containing the initialization x y z w data 78 | */ 79 | public TexCoord4f(Tuple4f t1) 80 | { 81 | super(t1); 82 | } 83 | 84 | 85 | /** 86 | * Constructs and initializes a TexCoord4f from the specified Tuple4d. 87 | * @param t1 the Tuple4d containing the initialization x y z w data 88 | */ 89 | public TexCoord4f(Tuple4d t1) 90 | { 91 | super(t1); 92 | } 93 | 94 | 95 | /** 96 | * Constructs and initializes a TexCoord4f to (0,0,0,0). 97 | */ 98 | public TexCoord4f() 99 | { 100 | super(); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /COPYRIGHT.txt: -------------------------------------------------------------------------------- 1 | Copyright 1996-2008 Sun Microsystems, Inc., 4150 Network Circle, Santa 2 | Clara, California 95054, U.S.A. All rights reserved. 3 | 4 | Sun Microsystems, Inc. has intellectual property rights relating to 5 | technology embodied in the product that is described in this 6 | document. In particular, and without limitation, these intellectual 7 | property rights may include one or more of the U.S. patents listed at 8 | http://www.sun.com/patents and one or more additional patents or 9 | pending patent applications in the U.S. and in other countries. 10 | 11 | U.S. Government Rights - Commercial software. Government users are 12 | subject to the Sun Microsystems, Inc. standard license agreement and 13 | applicable provisions of the FAR and its supplements. 14 | 15 | Use is subject to license terms. 16 | 17 | This distribution may include materials developed by third parties. 18 | 19 | Parts of the product may be derived from Berkeley BSD systems, 20 | licensed from the University of California. UNIX is a registered 21 | trademark in the U.S. and in other countries, exclusively licensed 22 | through X/Open Company, Ltd. 23 | 24 | Sun, Sun Microsystems, the Sun logo, Java, Solaris, Java 3D, the 100% 25 | Pure Java logo, the Duke logo and the Java Coffee Cup logo are 26 | trademarks or registered trademarks of Sun Microsystems, Inc. in the 27 | U.S. and other countries. 28 | 29 | This product is covered and controlled by U.S. Export Control laws and 30 | may be subject to the export or import laws in other countries. 31 | Nuclear, missile, chemical biological weapons or nuclear maritime end 32 | uses or end users, whether direct or indirect, are strictly 33 | prohibited. Export or reexport to countries subject to U.S. embargo or 34 | to entities identified on U.S. export exclusion lists, including, but 35 | not limited to, the denied persons and specially designated nationals 36 | lists is strictly prohibited. 37 | 38 | Copyright 1996-2008 Sun Microsystems, Inc., 4150 Network Circle, Santa 39 | Clara, California 95054, Etats-Unis. Tous droits réservés. 40 | 41 | Sun Microsystems, Inc. détient les droits de propriété intellectuels 42 | relatifs à la technologie incorporée dans le produit qui est décrit 43 | dans ce document. En particulier, et ce sans limitation, ces droits de 44 | propriété intellectuelle peuvent inclure un ou plus des brevets 45 | américains listés à l'adresse http://www.sun.com/patents et un ou les 46 | brevets supplémentaires ou les applications de brevet en attente aux 47 | Etats - Unis et dans les autres pays. 48 | 49 | L'utilisation est soumise aux termes de la Licence. 50 | 51 | Cette distribution peut comprendre des composants développés par des 52 | tierces parties. 53 | 54 | Des parties de ce produit pourront être dérivées des systèmes Berkeley 55 | BSD licenciés par l'Université de Californie. UNIX est une marque 56 | déposée aux Etats-Unis et dans d'autres pays et licenciée 57 | exclusivement par X/Open Company, Ltd. 58 | 59 | Sun, Sun Microsystems, le logo Sun, Java, Solaris, Java 3D, le logo 60 | 100% Pure Java, le logo Duke et le logo Java Coffee Cup sont des 61 | marques de fabrique ou des marques déposées de Sun Microsystems, 62 | Inc. aux Etats-Unis et dans d'autres pays. 63 | 64 | Ce produit est soumis à la législation américaine en matière de 65 | contrôle des exportations et peut être soumis à la règlementation en 66 | vigueur dans d'autres pays dans le domaine des exportations et 67 | importations. Les utilisations, ou utilisateurs finaux, pour des armes 68 | nucléaires,des missiles, des armes biologiques et chimiques ou du 69 | nucléaire maritime, directement ou indirectement, sont strictement 70 | interdites. Les exportations ou réexportations vers les pays sous 71 | embargo américain, ou vers des entités figurant sur les listes 72 | d'exclusion d'exportation américaines, y compris, mais de manière non 73 | exhaustive, la liste de personnes qui font objet d'un ordre de ne pas 74 | participer, d'une façon directe ou indirecte, aux exportations des 75 | produits ou des services qui sont régis par la législation américaine 76 | en matière de contrôle des exportations et la liste de ressortissants 77 | spécifiquement désignés, sont rigoureusement interdites. 78 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point2d.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 2 element point that is represented by double precision floating 32 | * point x,y coordinates. 33 | * 34 | */ 35 | public class Point2d extends Tuple2d implements java.io.Serializable { 36 | 37 | // Compatible with 1.1 38 | static final long serialVersionUID = 1133748791492571954L; 39 | 40 | /** 41 | * Constructs and initializes a Point2d from the specified xy coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | */ 45 | public Point2d(double x, double y) 46 | { 47 | super(x,y); 48 | } 49 | 50 | 51 | /** 52 | * Constructs and initializes a Point2d from the specified array. 53 | * @param p the array of length 2 containing xy in order 54 | */ 55 | public Point2d(double[] p) 56 | { 57 | super(p); 58 | } 59 | 60 | 61 | /** 62 | * Constructs and initializes a Point2d from the specified Point2d. 63 | * @param p1 the Point2d containing the initialization x y data 64 | */ 65 | public Point2d(Point2d p1) 66 | { 67 | super(p1); 68 | } 69 | 70 | 71 | /** 72 | * Constructs and initializes a Point2d from the specified Point2f. 73 | * @param p1 the Point2f containing the initialization x y data 74 | */ 75 | public Point2d(Point2f p1) 76 | { 77 | super(p1); 78 | } 79 | 80 | 81 | /** 82 | * Constructs and initializes a Point2d from the specified Tuple2d. 83 | * @param t1 the Tuple2d containing the initialization x y data 84 | */ 85 | public Point2d(Tuple2d t1) 86 | { 87 | super(t1); 88 | } 89 | 90 | 91 | /** 92 | * Constructs and initializes a Point2d from the specified Tuple2f. 93 | * @param t1 the Tuple2f containing the initialization x y data 94 | */ 95 | public Point2d(Tuple2f t1) 96 | { 97 | super(t1); 98 | } 99 | 100 | 101 | /** 102 | * Constructs and initializes a Point2d to (0,0). 103 | */ 104 | public Point2d() 105 | { 106 | super(); 107 | } 108 | 109 | /** 110 | * Computes the square of the distance between this point and point p1. 111 | * @param p1 the other point 112 | */ 113 | public final double distanceSquared(Point2d p1) 114 | { 115 | double dx, dy; 116 | 117 | dx = this.x-p1.x; 118 | dy = this.y-p1.y; 119 | return dx*dx+dy*dy; 120 | } 121 | 122 | /** 123 | * Computes the distance between this point and point p1. 124 | * @param p1 the other point 125 | */ 126 | public final double distance(Point2d p1) 127 | { 128 | double dx, dy; 129 | 130 | dx = this.x-p1.x; 131 | dy = this.y-p1.y; 132 | return Math.sqrt(dx*dx+dy*dy); 133 | } 134 | 135 | 136 | /** 137 | * Computes the L-1 (Manhattan) distance between this point and 138 | * point p1. The L-1 distance is equal to abs(x1-x2) + abs(y1-y2). 139 | * @param p1 the other point 140 | */ 141 | public final double distanceL1(Point2d p1) 142 | { 143 | return( Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y)); 144 | } 145 | 146 | /** 147 | * Computes the L-infinite distance between this point and 148 | * point p1. The L-infinite distance is equal to 149 | * MAX[abs(x1-x2), abs(y1-y2)]. 150 | * @param p1 the other point 151 | */ 152 | public final double distanceLinf(Point2d p1) 153 | { 154 | return(Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y))); 155 | } 156 | 157 | } 158 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point2f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 2 element point that is represented by single precision floating 32 | * point x,y coordinates. 33 | * 34 | */ 35 | public class Point2f extends Tuple2f implements java.io.Serializable { 36 | 37 | // Compatible with 1.1 38 | static final long serialVersionUID = -4801347926528714435L; 39 | 40 | /** 41 | * Constructs and initializes a Point2f from the specified xy coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | */ 45 | public Point2f(float x, float y) 46 | { 47 | super(x,y); 48 | } 49 | 50 | 51 | /** 52 | * Constructs and initializes a Point2f from the specified array. 53 | * @param p the array of length 2 containing xy in order 54 | */ 55 | public Point2f(float[] p) 56 | { 57 | super(p); 58 | } 59 | 60 | 61 | /** 62 | * Constructs and initializes a Point2f from the specified Point2f. 63 | * @param p1 the Point2f containing the initialization x y data 64 | */ 65 | public Point2f(Point2f p1) 66 | { 67 | super(p1); 68 | } 69 | 70 | /** 71 | * Constructs and initializes a Point2f from the specified Point2d. 72 | * @param p1 the Point2d containing the initialization x y z data 73 | */ 74 | public Point2f(Point2d p1) 75 | { 76 | super(p1); 77 | } 78 | 79 | 80 | 81 | /** 82 | * Constructs and initializes a Point2f from the specified Tuple2d. 83 | * @param t1 the Tuple2d containing the initialization x y z data 84 | */ 85 | public Point2f(Tuple2d t1) 86 | { 87 | super(t1); 88 | } 89 | 90 | 91 | 92 | /** 93 | * Constructs and initializes a Point2f from the specified Tuple2f. 94 | * @param t1 the Tuple2f containing the initialization x y data 95 | */ 96 | public Point2f(Tuple2f t1) 97 | { 98 | super(t1); 99 | } 100 | 101 | 102 | /** 103 | * Constructs and initializes a Point2f to (0,0). 104 | */ 105 | public Point2f() 106 | { 107 | super(); 108 | } 109 | 110 | /** 111 | * Computes the square of the distance between this point and point p1. 112 | * @param p1 the other point 113 | */ 114 | public final float distanceSquared(Point2f p1) 115 | { 116 | float dx, dy; 117 | 118 | dx = this.x-p1.x; 119 | dy = this.y-p1.y; 120 | return dx*dx+dy*dy; 121 | } 122 | 123 | /** 124 | * Computes the distance between this point and point p1. 125 | * @param p1 the other point 126 | */ 127 | public final float distance(Point2f p1) 128 | { 129 | float dx, dy; 130 | 131 | dx = this.x-p1.x; 132 | dy = this.y-p1.y; 133 | return (float) Math.sqrt(dx*dx+dy*dy); 134 | } 135 | 136 | 137 | /** 138 | * Computes the L-1 (Manhattan) distance between this point and 139 | * point p1. The L-1 distance is equal to abs(x1-x2) + abs(y1-y2). 140 | * @param p1 the other point 141 | */ 142 | public final float distanceL1(Point2f p1) 143 | { 144 | return( Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y)); 145 | } 146 | 147 | /** 148 | * Computes the L-infinite distance between this point and 149 | * point p1. The L-infinite distance is equal to 150 | * MAX[abs(x1-x2), abs(y1-y2)]. 151 | * @param p1 the other point 152 | */ 153 | public final float distanceLinf(Point2f p1) 154 | { 155 | return(Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y))); 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /src/javax/vecmath/Color3b.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | import java.awt.Color; 30 | 31 | 32 | /** 33 | * A three-byte color value represented by byte x, y, and z values. The 34 | * x, y, and z values represent the red, green, and blue values, 35 | * respectively. 36 | *37 | * Note that Java defines a byte as a signed integer in the range 38 | * [-128, 127]. However, colors are more typically represented by values 39 | * in the range [0, 255]. Java 3D recognizes this and for color 40 | * treats the bytes as if the range were [0, 255]---in other words, as 41 | * if the bytes were unsigned. 42 | *
43 | * Java 3D assumes that a linear (gamma-corrected) visual is used for 44 | * all colors. 45 | * 46 | */ 47 | public class Color3b extends Tuple3b implements java.io.Serializable { 48 | 49 | // Compatible with 1.1 50 | static final long serialVersionUID = 6632576088353444794L; 51 | 52 | /** 53 | * Constructs and initializes a Color3b from the specified three values. 54 | * @param c1 the red color value 55 | * @param c2 the green color value 56 | * @param c3 the blue color value 57 | */ 58 | public Color3b(byte c1, byte c2, byte c3) { 59 | super(c1,c2,c3); 60 | } 61 | 62 | 63 | /** 64 | * Constructs and initializes a Color3b from input array of length 3. 65 | * @param c the array of length 3 containing the r,g,b data in order 66 | */ 67 | public Color3b(byte[] c) { 68 | super(c); 69 | } 70 | 71 | 72 | /** 73 | * Constructs and initializes a Color3b from the specified Color3b. 74 | * @param c1 the Color3b containing the initialization r,g,b data 75 | */ 76 | public Color3b(Color3b c1) { 77 | super(c1); 78 | } 79 | 80 | 81 | /** 82 | * Constructs and initializes a Color3b from the specified Tuple3b. 83 | * @param t1 the Tuple3b containing the initialization r,g,b data 84 | */ 85 | public Color3b(Tuple3b t1) { 86 | super(t1); 87 | } 88 | 89 | 90 | /** 91 | * Constructs and initializes a Color3b from the specified AWT 92 | * Color object. The alpha value of the AWT color is ignored. 93 | * No conversion is done on the color to compensate for 94 | * gamma correction. 95 | * 96 | * @param color the AWT color with which to initialize this 97 | * Color3b object 98 | * 99 | * @since vecmath 1.2 100 | */ 101 | public Color3b(Color color) { 102 | super((byte)color.getRed(), 103 | (byte)color.getGreen(), 104 | (byte)color.getBlue()); 105 | } 106 | 107 | 108 | /** 109 | * Constructs and initializes a Color3b to (0,0,0). 110 | */ 111 | public Color3b() { 112 | super(); 113 | } 114 | 115 | 116 | /** 117 | * Sets the r,g,b values of this Color3b object to those of the 118 | * specified AWT Color object. 119 | * No conversion is done on the color to compensate for 120 | * gamma correction. 121 | * 122 | * @param color the AWT color to copy into this Color3b object 123 | * 124 | * @since vecmath 1.2 125 | */ 126 | public final void set(Color color) { 127 | x = (byte)color.getRed(); 128 | y = (byte)color.getGreen(); 129 | z = (byte)color.getBlue(); 130 | } 131 | 132 | 133 | /** 134 | * Returns a new AWT color object initialized with the r,g,b 135 | * values of this Color3b object. 136 | * 137 | * @return a new AWT Color object 138 | * 139 | * @since vecmath 1.2 140 | */ 141 | public final Color get() { 142 | int r = (int)x & 0xff; 143 | int g = (int)y & 0xff; 144 | int b = (int)z & 0xff; 145 | 146 | return new Color(r, g, b); 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /src/javax/vecmath/ExceptionStrings.properties: -------------------------------------------------------------------------------- 1 | Matrix3d0=Matrix3d setElement 2 | Matrix3d1=Matrix3d getElement 3 | Matrix3d2=Matrix3d getRow 4 | Matrix3d4=Matrix3d getColumn 5 | Matrix3d6=Matrix3d setRow 6 | Matrix3d9=Matrix3d setColumn 7 | Matrix3d12=cannot invert matrix 8 | Matrix3d13=Logic error: imax < 0 9 | Matrix3f0=Matrix3f setElement 10 | Matrix3f1=Matrix3d getRow 11 | Matrix3f3=Matrix3d getColumn 12 | Matrix3f5=Matrix3f getElement 13 | Matrix3f6=Matrix3f setRow 14 | Matrix3f9=Matrix3f setColumn 15 | Matrix3f12=cannot invert matrix 16 | Matrix3f13=Logic error: imax < 0 17 | Matrix4d0=Matrix4d setElement 18 | Matrix4d1=Matrix4d getElement 19 | Matrix4d2=Matrix4d getRow 20 | Matrix4d3=Matrix4d getColumn 21 | Matrix4d4=Matrix4d setRow 22 | Matrix4d7=Matrix4d setColumn 23 | Matrix4d10=cannot invert matrix 24 | Matrix4d11=Logic error: imax < 0 25 | Matrix4f0=Matrix4f setElement 26 | Matrix4f1=Matrix4f getElement 27 | Matrix4f2=Matrix4f getRow 28 | Matrix4f4=Matrix4f getColumn 29 | Matrix4f6=Matrix4f setRow 30 | Matrix4f9=Matrix4f setColumn 31 | Matrix4f12=cannot invert matrix 32 | Matrix4f13=Logic error: imax < 0 33 | GMatrix0=GMatrix.mul:array dimension mismatch 34 | GMatrix1=GMatrix.mul(GMatrix, GMatrix) dimension mismatch 35 | GMatrix2=GMatrix.mul(GVector, GVector): matrix does not have enough rows 36 | GMatrix3=GMatrix.mul(GVector, GVector): matrix does not have enough columns 37 | GMatrix4=GMatrix.add(GMatrix): row dimension mismatch 38 | GMatrix5=GMatrix.add(GMatrix): column dimension mismatch 39 | GMatrix6=GMatrix.add(GMatrix, GMatrix): row dimension mismatch 40 | GMatrix7=GMatrix.add(GMatrix, GMatrix): column dimension mismatch 41 | GMatrix8=GMatrix.add(GMatrix): input matrices dimensions do not match this matrix dimensions 42 | GMatrix9=GMatrix.sub(GMatrix): row dimension mismatch 43 | GMatrix10=GMatrix.sub(GMatrix, GMatrix): row dimension mismatch 44 | GMatrix11=GMatrix.sub(GMatrix, GMatrix): column dimension mismatch 45 | GMatrix12=GMatrix.sub(GMatrix, GMatrix): input matrix dimensions do not match dimensions for this matrix 46 | GMatrix13=GMatrix.negate(GMatrix, GMatrix): input matrix dimensions do not match dimensions for this matrix 47 | GMatrix14=GMatrix.mulTransposeBoth matrix dimension mismatch 48 | GMatrix15=GMatrix.mulTransposeRight matrix dimension mismatch 49 | GMatrix16=GMatrix.mulTransposeLeft matrix dimension mismatch 50 | GMatrix17=GMatrix.transpose(GMatrix) mismatch in matrix dimensions 51 | GMatrix18=GMatrix.SVD: dimension mismatch with V matrix 52 | GMatrix19=cannot perform LU decomposition on a non square matrix 53 | GMatrix20=row permutation must be same dimension as matrix 54 | GMatrix21=cannot invert matrix 55 | GMatrix22=cannot invert non square matrix 56 | GMatrix24=Logic error: imax < 0 57 | GMatrix25=GMatrix.SVD: dimension mismatch with U matrix 58 | GMatrix26=GMatrix.SVD: dimension mismatch with W matrix 59 | GMatrix27=LU must have same dimensions as this matrix 60 | GMatrix28=GMatrix.sub(GMatrix): column dimension mismatch 61 | GVector0=GVector.normalize( GVector) input vector and this vector lengths not matched 62 | GVector1=GVector.scale(double, GVector) input vector and this vector lengths not matched 63 | GVector2=GVector.scaleAdd(GVector, GVector) input vector dimensions not matched 64 | GVector3=GVector.scaleAdd(GVector, GVector) input vectors and this vector dimensions not matched 65 | GVector4=GVector.add(GVector) input vectors and this vector dimensions not matched 66 | GVector5=GVector.add(GVector, GVector) input vector dimensions not matched 67 | GVector6=GVector.add(GVector, GVector) input vectors and this vector dimensions not matched 68 | GVector7=GVector.sub(GVector) input vector and this vector dimensions not matched 69 | GVector8=GVector.sub(GVector, GVector) input vector dimensions not matched 70 | GVector9=GVector.sub(GMatrix, GVector) input vectors and this vector dimensions not matched 71 | GVector10=GVector.mul(GMatrix, GVector) matrix and vector dimensions not matched 72 | GVector11=GVector.mul(GMatrix, GVector) matrix this vector dimensions not matched 73 | GVector12=GVector.mul(GVector, GMatrix) matrix and vector dimensions not matched 74 | GVector13=GVector.mul(GVector, GMatrix) matrix this vector dimensions not matched 75 | GVector14=GVector.dot(GVector) input vector and this vector have different sizes 76 | GVector15=matrix dimensions are not compatible 77 | GVector16=b vector does not match matrix dimension 78 | GVector17=GVector.interpolate(GVector, GVector, float) input vectors have different lengths 79 | GVector18=GVector.interpolate(GVector, GVector, float) input vectors and this vector have different lengths 80 | GVector19=GVector.interpolate(GVector, float) input vector and this vector have different lengths 81 | GVector20=GVector.interpolate(GVector, GVector, double) input vectors have different lengths 82 | GVector21=GVector.interpolate(GVector, GVector, double) input vectors and this vector have different lengths 83 | GVector22=GVector.interpolate(GVector, double) input vectors and this vector have different lengths 84 | GVector23=matrix dimensions are not compatible 85 | GVector24=permutation vector does not match matrix dimension 86 | GVector25=LUDBackSolve non square matrix 87 | -------------------------------------------------------------------------------- /src/javax/vecmath/Color3f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | import java.awt.Color; 30 | 31 | 32 | /** 33 | * A three-element color value represented by single precision floating 34 | * point x,y,z values. The x,y,z values represent the red, green, and 35 | * blue color values, respectively. Color components should be in the 36 | * range of [0.0, 1.0]. 37 | *
38 | * Java 3D assumes that a linear (gamma-corrected) visual is used for 39 | * all colors. 40 | * 41 | */ 42 | public class Color3f extends Tuple3f implements java.io.Serializable { 43 | 44 | // Compatible with 1.1 45 | static final long serialVersionUID = -1861792981817493659L; 46 | 47 | /** 48 | * Constructs and initializes a Color3f from the three xyz values. 49 | * @param x the red color value 50 | * @param y the green color value 51 | * @param z the blue color value 52 | */ 53 | public Color3f(float x, float y, float z) { 54 | super(x,y,z); 55 | } 56 | 57 | 58 | /** 59 | * Constructs and initializes a Color3f from the array of length 3. 60 | * @param v the array of length 3 containing xyz in order 61 | */ 62 | public Color3f(float[] v) { 63 | super(v); 64 | } 65 | 66 | 67 | /** 68 | * Constructs and initializes a Color3f from the specified Color3f. 69 | * @param v1 the Color3f containing the initialization x y z data 70 | */ 71 | public Color3f(Color3f v1) { 72 | super(v1); 73 | } 74 | 75 | 76 | /** 77 | * Constructs and initializes a Color3f from the specified Tuple3f. 78 | * @param t1 the Tuple3f containing the initialization x y z data 79 | */ 80 | public Color3f(Tuple3f t1) { 81 | super(t1); 82 | } 83 | 84 | 85 | /** 86 | * Constructs and initializes a Color3f from the specified Tuple3d. 87 | * @param t1 the Tuple3d containing the initialization x y z data 88 | */ 89 | public Color3f(Tuple3d t1) { 90 | super(t1); 91 | } 92 | 93 | 94 | /** 95 | * Constructs and initializes a Color3f from the specified AWT 96 | * Color object. The alpha value of the AWT color is ignored. 97 | * No conversion is done on the color to compensate for 98 | * gamma correction. 99 | * 100 | * @param color the AWT color with which to initialize this 101 | * Color3f object 102 | * 103 | * @since vecmath 1.2 104 | */ 105 | public Color3f(Color color) { 106 | super((float)color.getRed() / 255.0f, 107 | (float)color.getGreen() / 255.0f, 108 | (float)color.getBlue() / 255.0f); 109 | } 110 | 111 | 112 | /** 113 | * Constructs and initializes a Color3f to (0.0, 0.0, 0.0). 114 | */ 115 | public Color3f() { 116 | super(); 117 | } 118 | 119 | 120 | /** 121 | * Sets the r,g,b values of this Color3f object to those of the 122 | * specified AWT Color object. 123 | * No conversion is done on the color to compensate for 124 | * gamma correction. 125 | * 126 | * @param color the AWT color to copy into this Color3f object 127 | * 128 | * @since vecmath 1.2 129 | */ 130 | public final void set(Color color) { 131 | x = (float)color.getRed() / 255.0f; 132 | y = (float)color.getGreen() / 255.0f; 133 | z = (float)color.getBlue() / 255.0f; 134 | } 135 | 136 | 137 | /** 138 | * Returns a new AWT color object initialized with the r,g,b 139 | * values of this Color3f object. 140 | * 141 | * @return a new AWT Color object 142 | * 143 | * @since vecmath 1.2 144 | */ 145 | public final Color get() { 146 | int r = Math.round(x * 255.0f); 147 | int g = Math.round(y * 255.0f); 148 | int b = Math.round(z * 255.0f); 149 | 150 | return new Color(r, g, b); 151 | } 152 | 153 | } 154 | -------------------------------------------------------------------------------- /src/javax/vecmath/Color4b.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | import java.awt.Color; 30 | 31 | 32 | /** 33 | * A four-byte color value represented by byte x, y, z, and w values. 34 | * The x, y, z, and w values represent the red, green, blue, and alpha 35 | * values, respectively. 36 | *
37 | * Note that Java defines a byte as a signed integer in the range 38 | * [-128, 127]. However, colors are more typically represented by values 39 | * in the range [0, 255]. Java 3D recognizes this and for color 40 | * treats the bytes as if the range were [0, 255]---in other words, as 41 | * if the bytes were unsigned. 42 | *
43 | * Java 3D assumes that a linear (gamma-corrected) visual is used for 44 | * all colors. 45 | * 46 | */ 47 | public class Color4b extends Tuple4b implements java.io.Serializable { 48 | 49 | // Compatible with 1.1 50 | static final long serialVersionUID = -105080578052502155L; 51 | 52 | /** 53 | * Constructs and initializes a Color4b from the four specified values. 54 | * @param b1 the red color value 55 | * @param b2 the green color value 56 | * @param b3 the blue color value 57 | * @param b4 the alpha value 58 | */ 59 | public Color4b(byte b1, byte b2, byte b3, byte b4) { 60 | super(b1,b2,b3,b4); 61 | } 62 | 63 | 64 | /** 65 | * Constructs and initializes a Color4b from the array of length 4. 66 | * @param c the array of length 4 containing r, g, b, and alpha in order 67 | */ 68 | public Color4b(byte[] c) { 69 | super(c); 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a Color4b from the specified Color4b. 75 | * @param c1 the Color4b containing the initialization r,g,b,a 76 | * data 77 | */ 78 | public Color4b(Color4b c1) { 79 | super(c1); 80 | } 81 | 82 | 83 | /** 84 | * Constructs and initializes a Color4b from the specified Tuple4b. 85 | * @param t1 the Tuple4b containing the initialization r,g,b,a 86 | * data 87 | */ 88 | public Color4b(Tuple4b t1) { 89 | super(t1); 90 | } 91 | 92 | 93 | /** 94 | * Constructs and initializes a Color4b from the specified AWT 95 | * Color object. 96 | * No conversion is done on the color to compensate for 97 | * gamma correction. 98 | * 99 | * @param color the AWT color with which to initialize this 100 | * Color4b object 101 | * 102 | * @since vecmath 1.2 103 | */ 104 | public Color4b(Color color) { 105 | super((byte)color.getRed(), 106 | (byte)color.getGreen(), 107 | (byte)color.getBlue(), 108 | (byte)color.getAlpha()); 109 | } 110 | 111 | 112 | /** 113 | * Constructs and initializes a Color4b to (0,0,0,0). 114 | */ 115 | public Color4b() { 116 | super(); 117 | } 118 | 119 | 120 | /** 121 | * Sets the r,g,b,a values of this Color4b object to those of the 122 | * specified AWT Color object. 123 | * No conversion is done on the color to compensate for 124 | * gamma correction. 125 | * 126 | * @param color the AWT color to copy into this Color4b object 127 | * 128 | * @since vecmath 1.2 129 | */ 130 | public final void set(Color color) { 131 | x = (byte)color.getRed(); 132 | y = (byte)color.getGreen(); 133 | z = (byte)color.getBlue(); 134 | w = (byte)color.getAlpha(); 135 | } 136 | 137 | 138 | /** 139 | * Returns a new AWT color object initialized with the r,g,b,a 140 | * values of this Color4b object. 141 | * 142 | * @return a new AWT Color object 143 | * 144 | * @since vecmath 1.2 145 | */ 146 | public final Color get() { 147 | int r = (int)x & 0xff; 148 | int g = (int)y & 0xff; 149 | int b = (int)z & 0xff; 150 | int a = (int)w & 0xff; 151 | 152 | return new Color(r, g, b, a); 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /src/javax/vecmath/Color4f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | import java.awt.Color; 30 | 31 | 32 | /** 33 | * A four-element color represented by single precision floating point 34 | * x, y, z, and w values. The x, y, z, and w values represent the red, 35 | * blue, green, and alpha color values, respectively. Color and alpha 36 | * components should be in the range [0.0, 1.0]. 37 | *
38 | * Java 3D assumes that a linear (gamma-corrected) visual is used for 39 | * all colors. 40 | * 41 | */ 42 | public class Color4f extends Tuple4f implements java.io.Serializable { 43 | 44 | // Compatible with 1.1 45 | static final long serialVersionUID = 8577680141580006740L; 46 | 47 | /** 48 | * Constructs and initializes a Color4f from the specified xyzw 49 | * coordinates. 50 | * @param x the red color value 51 | * @param y the green color value 52 | * @param z the blue color value 53 | * @param w the alpha value 54 | */ 55 | public Color4f(float x, float y, float z, float w) { 56 | super(x,y,z,w); 57 | } 58 | 59 | 60 | /** 61 | * Constructs and initializes a Color4f from the array of length 4. 62 | * @param c the array of length 4 containing r,g,b,a in order 63 | */ 64 | public Color4f(float[] c) { 65 | super(c); 66 | } 67 | 68 | 69 | /** 70 | * Constructs and initializes a Color4f from the specified Color4f. 71 | * @param c1 the Color4f containing the initialization r,g,b,a data 72 | */ 73 | public Color4f(Color4f c1) { 74 | super(c1); 75 | } 76 | 77 | 78 | /** 79 | * Constructs and initializes a Color4f from the specified Tuple4f. 80 | * @param t1 the Tuple4f containing the initialization r,g,b,a data 81 | */ 82 | public Color4f(Tuple4f t1) { 83 | super(t1); 84 | } 85 | 86 | 87 | /** 88 | * Constructs and initializes a Color4f from the specified Tuple4d. 89 | * @param t1 the Tuple4d containing the initialization r,g,b,a data 90 | */ 91 | public Color4f(Tuple4d t1) { 92 | super(t1); 93 | } 94 | 95 | 96 | /** 97 | * Constructs and initializes a Color4f from the specified AWT 98 | * Color object. 99 | * No conversion is done on the color to compensate for 100 | * gamma correction. 101 | * 102 | * @param color the AWT color with which to initialize this 103 | * Color4f object 104 | * 105 | * @since vecmath 1.2 106 | */ 107 | public Color4f(Color color) { 108 | super((float)color.getRed() / 255.0f, 109 | (float)color.getGreen() / 255.0f, 110 | (float)color.getBlue() / 255.0f, 111 | (float)color.getAlpha() / 255.0f); 112 | } 113 | 114 | 115 | /** 116 | * Constructs and initializes a Color4f to (0.0, 0.0, 0.0, 0.0). 117 | */ 118 | public Color4f() { 119 | super(); 120 | } 121 | 122 | 123 | /** 124 | * Sets the r,g,b,a values of this Color4f object to those of the 125 | * specified AWT Color object. 126 | * No conversion is done on the color to compensate for 127 | * gamma correction. 128 | * 129 | * @param color the AWT color to copy into this Color4f object 130 | * 131 | * @since vecmath 1.2 132 | */ 133 | public final void set(Color color) { 134 | x = (float)color.getRed() / 255.0f; 135 | y = (float)color.getGreen() / 255.0f; 136 | z = (float)color.getBlue() / 255.0f; 137 | w = (float)color.getAlpha() / 255.0f; 138 | } 139 | 140 | 141 | /** 142 | * Returns a new AWT color object initialized with the r,g,b,a 143 | * values of this Color4f object. 144 | * 145 | * @return a new AWT Color object 146 | * 147 | * @since vecmath 1.2 148 | */ 149 | public final Color get() { 150 | int r = Math.round(x * 255.0f); 151 | int g = Math.round(y * 255.0f); 152 | int b = Math.round(z * 255.0f); 153 | int a = Math.round(w * 255.0f); 154 | 155 | return new Color(r, g, b, a); 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /src/javax/vecmath/Vector2f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 2-element vector that is represented by single-precision floating 32 | * point x,y coordinates. 33 | * 34 | */ 35 | public class Vector2f extends Tuple2f implements java.io.Serializable { 36 | 37 | // Combatible with 1.1 38 | static final long serialVersionUID = -2168194326883512320L; 39 | 40 | /** 41 | * Constructs and initializes a Vector2f from the specified xy coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | */ 45 | public Vector2f(float x, float y) 46 | { 47 | super(x,y); 48 | } 49 | 50 | 51 | /** 52 | * Constructs and initializes a Vector2f from the specified array. 53 | * @param v the array of length 2 containing xy in order 54 | */ 55 | public Vector2f(float[] v) 56 | { 57 | super(v); 58 | } 59 | 60 | 61 | /** 62 | * Constructs and initializes a Vector2f from the specified Vector2f. 63 | * @param v1 the Vector2f containing the initialization x y data 64 | */ 65 | public Vector2f(Vector2f v1) 66 | { 67 | super(v1); 68 | } 69 | 70 | 71 | /** 72 | * Constructs and initializes a Vector2f from the specified Vector2d. 73 | * @param v1 the Vector2d containing the initialization x y data 74 | */ 75 | public Vector2f(Vector2d v1) 76 | { 77 | super(v1); 78 | } 79 | 80 | 81 | /** 82 | * Constructs and initializes a Vector2f from the specified Tuple2f. 83 | * @param t1 the Tuple2f containing the initialization x y data 84 | */ 85 | public Vector2f(Tuple2f t1) 86 | { 87 | super(t1); 88 | } 89 | 90 | 91 | /** 92 | * Constructs and initializes a Vector2f from the specified Tuple2d. 93 | * @param t1 the Tuple2d containing the initialization x y data 94 | */ 95 | public Vector2f(Tuple2d t1) 96 | { 97 | super(t1); 98 | } 99 | 100 | 101 | 102 | /** 103 | * Constructs and initializes a Vector2f to (0,0). 104 | */ 105 | public Vector2f() 106 | { 107 | super(); 108 | } 109 | 110 | 111 | /** 112 | * Computes the dot product of the this vector and vector v1. 113 | * @param v1 the other vector 114 | */ 115 | public final float dot(Vector2f v1) 116 | { 117 | return (this.x*v1.x + this.y*v1.y); 118 | } 119 | 120 | 121 | /** 122 | * Returns the length of this vector. 123 | * @return the length of this vector 124 | */ 125 | public final float length() 126 | { 127 | return (float) Math.sqrt(this.x*this.x + this.y*this.y); 128 | } 129 | 130 | /** 131 | * Returns the squared length of this vector. 132 | * @return the squared length of this vector 133 | */ 134 | public final float lengthSquared() 135 | { 136 | return (this.x*this.x + this.y*this.y); 137 | } 138 | 139 | /** 140 | * Sets the value of this vector to the normalization of vector v1. 141 | * @param v1 the un-normalized vector 142 | */ 143 | public final void normalize(Vector2f v1) 144 | { 145 | float norm; 146 | 147 | norm = (float) (1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y)); 148 | this.x = v1.x*norm; 149 | this.y = v1.y*norm; 150 | } 151 | 152 | /** 153 | * Normalizes this vector in place. 154 | */ 155 | public final void normalize() 156 | { 157 | float norm; 158 | 159 | norm = (float) 160 | (1.0/Math.sqrt(this.x*this.x + this.y*this.y)); 161 | this.x *= norm; 162 | this.y *= norm; 163 | } 164 | 165 | 166 | /** 167 | * Returns the angle in radians between this vector and the vector 168 | * parameter; the return value is constrained to the range [0,PI]. 169 | * @param v1 the other vector 170 | * @return the angle in radians in the range [0,PI] 171 | */ 172 | public final float angle(Vector2f v1) 173 | { 174 | double vDot = this.dot(v1) / ( this.length()*v1.length() ); 175 | if( vDot < -1.0) vDot = -1.0; 176 | if( vDot > 1.0) vDot = 1.0; 177 | return((float) (Math.acos( vDot ))); 178 | } 179 | 180 | 181 | } 182 | -------------------------------------------------------------------------------- /src/javax/vecmath/Vector2d.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 2-element vector that is represented by double-precision floating 32 | * point x,y coordinates. 33 | * 34 | */ 35 | public class Vector2d extends Tuple2d implements java.io.Serializable { 36 | 37 | // Combatible with 1.1 38 | static final long serialVersionUID = 8572646365302599857L; 39 | 40 | /** 41 | * Constructs and initializes a Vector2d from the specified xy coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | */ 45 | public Vector2d(double x, double y) 46 | { 47 | super(x,y); 48 | } 49 | 50 | 51 | /** 52 | * Constructs and initializes a Vector2d from the specified array. 53 | * @param v the array of length 2 containing xy in order 54 | */ 55 | public Vector2d(double[] v) 56 | { 57 | super(v); 58 | } 59 | 60 | 61 | /** 62 | * Constructs and initializes a Vector2d from the specified Vector2d. 63 | * @param v1 the Vector2d containing the initialization x y data 64 | */ 65 | public Vector2d(Vector2d v1) 66 | { 67 | super(v1); 68 | } 69 | 70 | 71 | /** 72 | * Constructs and initializes a Vector2d from the specified Vector2f. 73 | * @param v1 the Vector2f containing the initialization x y data 74 | */ 75 | public Vector2d(Vector2f v1) 76 | { 77 | super(v1); 78 | } 79 | 80 | 81 | /** 82 | * Constructs and initializes a Vector2d from the specified Tuple2d. 83 | * @param t1 the Tuple2d containing the initialization x y data 84 | */ 85 | public Vector2d(Tuple2d t1) 86 | { 87 | super(t1); 88 | } 89 | 90 | 91 | /** 92 | * Constructs and initializes a Vector2d from the specified Tuple2f. 93 | * @param t1 the Tuple2f containing the initialization x y data 94 | */ 95 | public Vector2d(Tuple2f t1) 96 | { 97 | super(t1); 98 | } 99 | 100 | 101 | /** 102 | * Constructs and initializes a Vector2d to (0,0). 103 | */ 104 | public Vector2d() 105 | { 106 | super(); 107 | } 108 | 109 | 110 | /** 111 | * Computes the dot product of the this vector and vector v1. 112 | * @param v1 the other vector 113 | */ 114 | public final double dot(Vector2d v1) 115 | { 116 | return (this.x*v1.x + this.y*v1.y); 117 | } 118 | 119 | 120 | /** 121 | * Returns the length of this vector. 122 | * @return the length of this vector 123 | */ 124 | public final double length() 125 | { 126 | return (double) Math.sqrt(this.x*this.x + this.y*this.y); 127 | } 128 | 129 | /** 130 | * Returns the squared length of this vector. 131 | * @return the squared length of this vector 132 | */ 133 | public final double lengthSquared() 134 | { 135 | return (this.x*this.x + this.y*this.y); 136 | } 137 | 138 | /** 139 | * Sets the value of this vector to the normalization of vector v1. 140 | * @param v1 the un-normalized vector 141 | */ 142 | public final void normalize(Vector2d v1) 143 | { 144 | double norm; 145 | 146 | norm = (double) (1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y)); 147 | this.x = v1.x*norm; 148 | this.y = v1.y*norm; 149 | } 150 | 151 | /** 152 | * Normalizes this vector in place. 153 | */ 154 | public final void normalize() 155 | { 156 | double norm; 157 | 158 | norm = (double) 159 | (1.0/Math.sqrt(this.x*this.x + this.y*this.y)); 160 | this.x *= norm; 161 | this.y *= norm; 162 | } 163 | 164 | 165 | /** 166 | * Returns the angle in radians between this vector and the vector 167 | * parameter; the return value is constrained to the range [0,PI]. 168 | * @param v1 the other vector 169 | * @return the angle in radians in the range [0,PI] 170 | */ 171 | public final double angle(Vector2d v1) 172 | { 173 | double vDot = this.dot(v1) / ( this.length()*v1.length() ); 174 | if( vDot < -1.0) vDot = -1.0; 175 | if( vDot > 1.0) vDot = 1.0; 176 | return((double) (Math.acos( vDot ))); 177 | 178 | } 179 | 180 | 181 | } 182 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point3d.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 3 element point that is represented by double precision floating point 32 | * x,y,z coordinates. 33 | * 34 | */ 35 | public class Point3d extends Tuple3d implements java.io.Serializable { 36 | 37 | // Compatible with 1.1 38 | static final long serialVersionUID = 5718062286069042927L; 39 | 40 | /** 41 | * Constructs and initializes a Point3d from the specified xyz coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | * @param z the z coordinate 45 | */ 46 | public Point3d(double x, double y, double z) 47 | { 48 | super(x,y,z); 49 | } 50 | 51 | 52 | /** 53 | * Constructs and initializes a Point3d from the array of length 3. 54 | * @param p the array of length 3 containing xyz in order 55 | */ 56 | public Point3d(double[] p) 57 | { 58 | super(p); 59 | } 60 | 61 | 62 | /** 63 | * Constructs and initializes a Point3d from the specified Point3d. 64 | * @param p1 the Point3d containing the initialization x y z data 65 | */ 66 | public Point3d(Point3d p1) 67 | { 68 | super(p1); 69 | } 70 | 71 | 72 | /** 73 | * Constructs and initializes a Point3d from the specified Point3f. 74 | * @param p1 the Point3f containing the initialization x y z data 75 | */ 76 | public Point3d(Point3f p1) 77 | { 78 | super(p1); 79 | } 80 | 81 | 82 | /** 83 | * Constructs and initializes a Point3d from the specified Tuple3f. 84 | * @param t1 the Tuple3f containing the initialization x y z data 85 | */ 86 | public Point3d(Tuple3f t1) 87 | { 88 | super(t1); 89 | } 90 | 91 | 92 | /** 93 | * Constructs and initializes a Point3d from the specified Tuple3d. 94 | * @param t1 the Tuple3d containing the initialization x y z data 95 | */ 96 | public Point3d(Tuple3d t1) 97 | { 98 | super(t1); 99 | } 100 | 101 | 102 | /** 103 | * Constructs and initializes a Point3d to (0,0,0). 104 | */ 105 | public Point3d() 106 | { 107 | super(); 108 | } 109 | 110 | 111 | /** 112 | * Returns the square of the distance between this point and point p1. 113 | * @param p1 the other point 114 | * @return the square of the distance 115 | */ 116 | public final double distanceSquared(Point3d p1) 117 | { 118 | double dx, dy, dz; 119 | 120 | dx = this.x-p1.x; 121 | dy = this.y-p1.y; 122 | dz = this.z-p1.z; 123 | return (dx*dx+dy*dy+dz*dz); 124 | } 125 | 126 | 127 | /** 128 | * Returns the distance between this point and point p1. 129 | * @param p1 the other point 130 | * @return the distance 131 | */ 132 | public final double distance(Point3d p1) 133 | { 134 | double dx, dy, dz; 135 | 136 | dx = this.x-p1.x; 137 | dy = this.y-p1.y; 138 | dz = this.z-p1.z; 139 | return Math.sqrt(dx*dx+dy*dy+dz*dz); 140 | } 141 | 142 | 143 | /** 144 | * Computes the L-1 (Manhattan) distance between this point and 145 | * point p1. The L-1 distance is equal to: 146 | * abs(x1-x2) + abs(y1-y2) + abs(z1-z2). 147 | * @param p1 the other point 148 | * @return the L-1 distance 149 | */ 150 | public final double distanceL1(Point3d p1) { 151 | return Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) + 152 | Math.abs(this.z-p1.z); 153 | } 154 | 155 | 156 | /** 157 | * Computes the L-infinite distance between this point and 158 | * point p1. The L-infinite distance is equal to 159 | * MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2)]. 160 | * @param p1 the other point 161 | * @return the L-infinite distance 162 | */ 163 | public final double distanceLinf(Point3d p1) { 164 | double tmp; 165 | tmp = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y)); 166 | 167 | return Math.max(tmp,Math.abs(this.z-p1.z)); 168 | } 169 | 170 | 171 | /** 172 | * Multiplies each of the x,y,z components of the Point4d parameter 173 | * by 1/w and places the projected values into this point. 174 | * @param p1 the source Point4d, which is not modified 175 | */ 176 | public final void project(Point4d p1) 177 | { 178 | double oneOw; 179 | 180 | oneOw = 1/p1.w; 181 | x = p1.x*oneOw; 182 | y = p1.y*oneOw; 183 | z = p1.z*oneOw; 184 | 185 | } 186 | 187 | 188 | } 189 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point3f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 3 element point that is represented by single precision floating point 32 | * x,y,z coordinates. 33 | * 34 | */ 35 | public class Point3f extends Tuple3f implements java.io.Serializable { 36 | 37 | 38 | // Compatible with 1.1 39 | static final long serialVersionUID = -8689337816398030143L; 40 | 41 | /** 42 | * Constructs and initializes a Point3f from the specified xyz coordinates. 43 | * @param x the x coordinate 44 | * @param y the y coordinate 45 | * @param z the z coordinate 46 | */ 47 | public Point3f(float x, float y, float z) 48 | { 49 | super(x,y,z); 50 | } 51 | 52 | 53 | /** 54 | * Constructs and initializes a Point3f from the array of length 3. 55 | * @param p the array of length 3 containing xyz in order 56 | */ 57 | public Point3f(float[] p) 58 | { 59 | super(p); 60 | } 61 | 62 | 63 | /** 64 | * Constructs and initializes a Point3f from the specified Point3f. 65 | * @param p1 the Point3f containing the initialization x y z data 66 | */ 67 | public Point3f(Point3f p1) 68 | { 69 | super(p1); 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a Point3f from the specified Point3d. 75 | * @param p1 the Point3d containing the initialization x y z data 76 | */ 77 | public Point3f(Point3d p1) 78 | { 79 | super(p1); 80 | } 81 | 82 | 83 | /** 84 | * Constructs and initializes a Point3f from the specified Tuple3f. 85 | * @param t1 the Tuple3f containing the initialization x y z data 86 | */ 87 | public Point3f(Tuple3f t1) 88 | { 89 | super(t1); 90 | } 91 | 92 | 93 | /** 94 | * Constructs and initializes a Point3f from the specified Tuple3d. 95 | * @param t1 the Tuple3d containing the initialization x y z data 96 | */ 97 | public Point3f(Tuple3d t1) 98 | { 99 | super(t1); 100 | } 101 | 102 | 103 | /** 104 | * Constructs and initializes a Point3f to (0,0,0). 105 | */ 106 | public Point3f() 107 | { 108 | super(); 109 | } 110 | 111 | 112 | /** 113 | * Computes the square of the distance between this point and 114 | * point p1. 115 | * @param p1 the other point 116 | * @return the square of the distance 117 | */ 118 | public final float distanceSquared(Point3f p1) 119 | { 120 | float dx, dy, dz; 121 | 122 | dx = this.x-p1.x; 123 | dy = this.y-p1.y; 124 | dz = this.z-p1.z; 125 | return dx*dx+dy*dy+dz*dz; 126 | } 127 | 128 | 129 | /** 130 | * Computes the distance between this point and point p1. 131 | * @param p1 the other point 132 | * @return the distance 133 | */ 134 | public final float distance(Point3f p1) 135 | { 136 | float dx, dy, dz; 137 | 138 | dx = this.x-p1.x; 139 | dy = this.y-p1.y; 140 | dz = this.z-p1.z; 141 | return (float) Math.sqrt(dx*dx+dy*dy+dz*dz); 142 | } 143 | 144 | 145 | /** 146 | * Computes the L-1 (Manhattan) distance between this point and 147 | * point p1. The L-1 distance is equal to: 148 | * abs(x1-x2) + abs(y1-y2) + abs(z1-z2). 149 | * @param p1 the other point 150 | * @return the L-1 distance 151 | */ 152 | public final float distanceL1(Point3f p1) 153 | { 154 | return( Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) + Math.abs(this.z-p1.z)); 155 | } 156 | 157 | 158 | /** 159 | * Computes the L-infinite distance between this point and 160 | * point p1. The L-infinite distance is equal to 161 | * MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2)]. 162 | * @param p1 the other point 163 | * @return the L-infinite distance 164 | */ 165 | public final float distanceLinf(Point3f p1) 166 | { 167 | float tmp; 168 | tmp = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y)); 169 | return(Math.max(tmp,Math.abs(this.z-p1.z))); 170 | 171 | } 172 | 173 | 174 | /** 175 | * Multiplies each of the x,y,z components of the Point4f parameter 176 | * by 1/w and places the projected values into this point. 177 | * @param p1 the source Point4f, which is not modified 178 | */ 179 | public final void project(Point4f p1) 180 | { 181 | float oneOw; 182 | 183 | oneOw = 1/p1.w; 184 | x = p1.x*oneOw; 185 | y = p1.y*oneOw; 186 | z = p1.z*oneOw; 187 | 188 | } 189 | 190 | 191 | } 192 | -------------------------------------------------------------------------------- /src/javax/vecmath/Vector3d.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 3-element vector that is represented by double-precision floating point 32 | * x,y,z coordinates. If this value represents a normal, then it should 33 | * be normalized. 34 | * 35 | */ 36 | public class Vector3d extends Tuple3d implements java.io.Serializable { 37 | 38 | // Combatible with 1.1 39 | static final long serialVersionUID = 3761969948420550442L; 40 | 41 | /** 42 | * Constructs and initializes a Vector3d from the specified xyz coordinates. 43 | * @param x the x coordinate 44 | * @param y the y coordinate 45 | * @param z the z coordinate 46 | */ 47 | public Vector3d(double x, double y, double z) 48 | { 49 | super(x,y,z); 50 | } 51 | 52 | 53 | /** 54 | * Constructs and initializes a Vector3d from the array of length 3. 55 | * @param v the array of length 3 containing xyz in order 56 | */ 57 | public Vector3d(double[] v) 58 | { 59 | super(v); 60 | } 61 | 62 | 63 | /** 64 | * Constructs and initializes a Vector3d from the specified Vector3d. 65 | * @param v1 the Vector3d containing the initialization x y z data 66 | */ 67 | public Vector3d(Vector3d v1) 68 | { 69 | super(v1); 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a Vector3d from the specified Vector3f. 75 | * @param v1 the Vector3f containing the initialization x y z data 76 | */ 77 | public Vector3d(Vector3f v1) 78 | { 79 | super(v1); 80 | } 81 | 82 | 83 | /** 84 | * Constructs and initializes a Vector3d from the specified Tuple3f. 85 | * @param t1 the Tuple3f containing the initialization x y z data 86 | */ 87 | public Vector3d(Tuple3f t1) 88 | { 89 | super(t1); 90 | } 91 | 92 | 93 | /** 94 | * Constructs and initializes a Vector3d from the specified Tuple3d. 95 | * @param t1 the Tuple3d containing the initialization x y z data 96 | */ 97 | public Vector3d(Tuple3d t1) 98 | { 99 | super(t1); 100 | } 101 | 102 | 103 | /** 104 | * Constructs and initializes a Vector3d to (0,0,0). 105 | */ 106 | public Vector3d() 107 | { 108 | super(); 109 | } 110 | 111 | 112 | /** 113 | * Sets this vector to the vector cross product of vectors v1 and v2. 114 | * @param v1 the first vector 115 | * @param v2 the second vector 116 | */ 117 | public final void cross(Vector3d v1, Vector3d v2) 118 | { 119 | double x,y; 120 | 121 | x = v1.y*v2.z - v1.z*v2.y; 122 | y = v2.x*v1.z - v2.z*v1.x; 123 | this.z = v1.x*v2.y - v1.y*v2.x; 124 | this.x = x; 125 | this.y = y; 126 | } 127 | 128 | 129 | /** 130 | * Sets the value of this vector to the normalization of vector v1. 131 | * @param v1 the un-normalized vector 132 | */ 133 | public final void normalize(Vector3d v1) 134 | { 135 | double norm; 136 | 137 | norm = 1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z); 138 | this.x = v1.x*norm; 139 | this.y = v1.y*norm; 140 | this.z = v1.z*norm; 141 | } 142 | 143 | 144 | /** 145 | * Normalizes this vector in place. 146 | */ 147 | public final void normalize() 148 | { 149 | double norm; 150 | 151 | norm = 1.0/Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z); 152 | this.x *= norm; 153 | this.y *= norm; 154 | this.z *= norm; 155 | } 156 | 157 | 158 | /** 159 | * Returns the dot product of this vector and vector v1. 160 | * @param v1 the other vector 161 | * @return the dot product of this and v1 162 | */ 163 | public final double dot(Vector3d v1) 164 | { 165 | return (this.x*v1.x + this.y*v1.y + this.z*v1.z); 166 | } 167 | 168 | 169 | /** 170 | * Returns the squared length of this vector. 171 | * @return the squared length of this vector 172 | */ 173 | public final double lengthSquared() 174 | { 175 | return (this.x*this.x + this.y*this.y + this.z*this.z); 176 | } 177 | 178 | 179 | /** 180 | * Returns the length of this vector. 181 | * @return the length of this vector 182 | */ 183 | public final double length() 184 | { 185 | return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z); 186 | } 187 | 188 | 189 | /** 190 | * Returns the angle in radians between this vector and the vector 191 | * parameter; the return value is constrained to the range [0,PI]. 192 | * @param v1 the other vector 193 | * @return the angle in radians in the range [0,PI] 194 | */ 195 | public final double angle(Vector3d v1) 196 | { 197 | double vDot = this.dot(v1) / ( this.length()*v1.length() ); 198 | if( vDot < -1.0) vDot = -1.0; 199 | if( vDot > 1.0) vDot = 1.0; 200 | return((double) (Math.acos( vDot ))); 201 | } 202 | 203 | 204 | } 205 | -------------------------------------------------------------------------------- /src/javax/vecmath/Vector3f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 3-element vector that is represented by single-precision floating point 32 | * x,y,z coordinates. If this value represents a normal, then it should 33 | * be normalized. 34 | * 35 | */ 36 | public class Vector3f extends Tuple3f implements java.io.Serializable { 37 | 38 | // Combatible with 1.1 39 | static final long serialVersionUID = -7031930069184524614L; 40 | 41 | /** 42 | * Constructs and initializes a Vector3f from the specified xyz coordinates. 43 | * @param x the x coordinate 44 | * @param y the y coordinate 45 | * @param z the z coordinate 46 | */ 47 | public Vector3f(float x, float y, float z) 48 | { 49 | super(x,y,z); 50 | } 51 | 52 | 53 | /** 54 | * Constructs and initializes a Vector3f from the array of length 3. 55 | * @param v the array of length 3 containing xyz in order 56 | */ 57 | public Vector3f(float[] v) 58 | { 59 | super(v); 60 | } 61 | 62 | 63 | /** 64 | * Constructs and initializes a Vector3f from the specified Vector3f. 65 | * @param v1 the Vector3f containing the initialization x y z data 66 | */ 67 | public Vector3f(Vector3f v1) 68 | { 69 | super(v1); 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a Vector3f from the specified Vector3d. 75 | * @param v1 the Vector3d containing the initialization x y z data 76 | */ 77 | public Vector3f(Vector3d v1) 78 | { 79 | super(v1); 80 | } 81 | 82 | 83 | /** 84 | * Constructs and initializes a Vector3f from the specified Tuple3f. 85 | * @param t1 the Tuple3f containing the initialization x y z data 86 | */ 87 | public Vector3f(Tuple3f t1) { 88 | super(t1); 89 | } 90 | 91 | 92 | /** 93 | * Constructs and initializes a Vector3f from the specified Tuple3d. 94 | * @param t1 the Tuple3d containing the initialization x y z data 95 | */ 96 | public Vector3f(Tuple3d t1) { 97 | super(t1); 98 | } 99 | 100 | 101 | /** 102 | * Constructs and initializes a Vector3f to (0,0,0). 103 | */ 104 | public Vector3f() 105 | { 106 | super(); 107 | } 108 | 109 | 110 | /** 111 | * Returns the squared length of this vector. 112 | * @return the squared length of this vector 113 | */ 114 | public final float lengthSquared() 115 | { 116 | return (this.x*this.x + this.y*this.y + this.z*this.z); 117 | } 118 | 119 | /** 120 | * Returns the length of this vector. 121 | * @return the length of this vector 122 | */ 123 | public final float length() 124 | { 125 | return (float) 126 | Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z); 127 | } 128 | 129 | 130 | /** 131 | * Sets this vector to be the vector cross product of vectors v1 and v2. 132 | * @param v1 the first vector 133 | * @param v2 the second vector 134 | */ 135 | public final void cross(Vector3f v1, Vector3f v2) 136 | { 137 | float x,y; 138 | 139 | x = v1.y*v2.z - v1.z*v2.y; 140 | y = v2.x*v1.z - v2.z*v1.x; 141 | this.z = v1.x*v2.y - v1.y*v2.x; 142 | this.x = x; 143 | this.y = y; 144 | } 145 | 146 | /** 147 | * Computes the dot product of this vector and vector v1. 148 | * @param v1 the other vector 149 | * @return the dot product of this vector and v1 150 | */ 151 | public final float dot(Vector3f v1) 152 | { 153 | return (this.x*v1.x + this.y*v1.y + this.z*v1.z); 154 | } 155 | 156 | /** 157 | * Sets the value of this vector to the normalization of vector v1. 158 | * @param v1 the un-normalized vector 159 | */ 160 | public final void normalize(Vector3f v1) 161 | { 162 | float norm; 163 | 164 | norm = (float) (1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z)); 165 | this.x = v1.x*norm; 166 | this.y = v1.y*norm; 167 | this.z = v1.z*norm; 168 | } 169 | 170 | /** 171 | * Normalizes this vector in place. 172 | */ 173 | public final void normalize() 174 | { 175 | float norm; 176 | 177 | norm = (float) 178 | (1.0/Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z)); 179 | this.x *= norm; 180 | this.y *= norm; 181 | this.z *= norm; 182 | } 183 | 184 | 185 | /** 186 | * Returns the angle in radians between this vector and the vector 187 | * parameter; the return value is constrained to the range [0,PI]. 188 | * @param v1 the other vector 189 | * @return the angle in radians in the range [0,PI] 190 | */ 191 | public final float angle(Vector3f v1) 192 | { 193 | double vDot = this.dot(v1) / ( this.length()*v1.length() ); 194 | if( vDot < -1.0) vDot = -1.0; 195 | if( vDot > 1.0) vDot = 1.0; 196 | return((float) (Math.acos( vDot ))); 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /src/javax/vecmath/Vector4f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 4-element vector represented by single-precision floating point x,y,z,w 32 | * coordinates. 33 | * 34 | */ 35 | public class Vector4f extends Tuple4f implements java.io.Serializable { 36 | 37 | // Compatible with 1.1 38 | static final long serialVersionUID = 8749319902347760659L; 39 | 40 | /** 41 | * Constructs and initializes a Vector4f from the specified xyzw coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | * @param z the z coordinate 45 | * @param w the w coordinate 46 | */ 47 | public Vector4f(float x, float y, float z, float w) 48 | { 49 | super(x,y,z,w); 50 | } 51 | 52 | 53 | /** 54 | * Constructs and initializes a Vector4f from the array of length 4. 55 | * @param v the array of length 4 containing xyzw in order 56 | */ 57 | public Vector4f(float[] v) 58 | { 59 | super(v); 60 | } 61 | 62 | 63 | /** 64 | * Constructs and initializes a Vector4f from the specified Vector4f. 65 | * @param v1 the Vector4f containing the initialization x y z w data 66 | */ 67 | public Vector4f(Vector4f v1) 68 | { 69 | super(v1); 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a Vector4f from the specified Vector4d. 75 | * @param v1 the Vector4d containing the initialization x y z w data 76 | */ 77 | public Vector4f(Vector4d v1) 78 | { 79 | super(v1); 80 | } 81 | 82 | 83 | /** 84 | * Constructs and initializes a Vector4f from the specified Tuple4f. 85 | * @param t1 the Tuple4f containing the initialization x y z w data 86 | */ 87 | public Vector4f(Tuple4f t1) 88 | { 89 | super(t1); 90 | } 91 | 92 | 93 | /** 94 | * Constructs and initializes a Vector4f from the specified Tuple4d. 95 | * @param t1 the Tuple4d containing the initialization x y z w data 96 | */ 97 | public Vector4f(Tuple4d t1) 98 | { 99 | super(t1); 100 | } 101 | 102 | 103 | /** 104 | * Constructs and initializes a Vector4f from the specified Tuple3f. 105 | * The x,y,z components of this vector are set to the corresponding 106 | * components of tuple t1. The w component of this vector 107 | * is set to 0. 108 | * @param t1 the tuple to be copied 109 | * 110 | * @since vecmath 1.2 111 | */ 112 | public Vector4f(Tuple3f t1) { 113 | super(t1.x, t1.y, t1.z, 0.0f); 114 | } 115 | 116 | 117 | /** 118 | * Constructs and initializes a Vector4f to (0,0,0,0). 119 | */ 120 | public Vector4f() 121 | { 122 | super(); 123 | } 124 | 125 | 126 | /** 127 | * Sets the x,y,z components of this vector to the corresponding 128 | * components of tuple t1. The w component of this vector 129 | * is set to 0. 130 | * @param t1 the tuple to be copied 131 | * 132 | * @since vecmath 1.2 133 | */ 134 | public final void set(Tuple3f t1) { 135 | this.x = t1.x; 136 | this.y = t1.y; 137 | this.z = t1.z; 138 | this.w = 0.0f; 139 | } 140 | 141 | 142 | /** 143 | * Returns the length of this vector. 144 | * @return the length of this vector as a float 145 | */ 146 | public final float length() 147 | { 148 | return 149 | (float) Math.sqrt(this.x*this.x + this.y*this.y + 150 | this.z*this.z + this.w*this.w); 151 | } 152 | 153 | /** 154 | * Returns the squared length of this vector 155 | * @return the squared length of this vector as a float 156 | */ 157 | public final float lengthSquared() 158 | { 159 | return (this.x*this.x + this.y*this.y + 160 | this.z*this.z + this.w*this.w); 161 | } 162 | 163 | /** 164 | * returns the dot product of this vector and v1 165 | * @param v1 the other vector 166 | * @return the dot product of this vector and v1 167 | */ 168 | public final float dot(Vector4f v1) 169 | { 170 | return (this.x*v1.x + this.y*v1.y + this.z*v1.z + this.w*v1.w); 171 | } 172 | 173 | 174 | /** 175 | * Sets the value of this vector to the normalization of vector v1. 176 | * @param v1 the un-normalized vector 177 | */ 178 | public final void normalize(Vector4f v1) 179 | { 180 | float norm; 181 | 182 | norm = (float) (1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y + 183 | v1.z*v1.z + v1.w*v1.w)); 184 | this.x = v1.x*norm; 185 | this.y = v1.y*norm; 186 | this.z = v1.z*norm; 187 | this.w = v1.w*norm; 188 | } 189 | 190 | 191 | /** 192 | * Normalizes this vector in place. 193 | */ 194 | public final void normalize() 195 | { 196 | float norm; 197 | 198 | norm = (float) (1.0/Math.sqrt(this.x*this.x + this.y*this.y + 199 | this.z*this.z + this.w*this.w)); 200 | this.x *= norm; 201 | this.y *= norm; 202 | this.z *= norm; 203 | this.w *= norm; 204 | } 205 | 206 | 207 | /** 208 | * Returns the (4-space) angle in radians between this vector and 209 | * the vector parameter; the return value is constrained to the 210 | * range [0,PI]. 211 | * @param v1 the other vector 212 | * @return the angle in radians in the range [0,PI] 213 | */ 214 | public final float angle(Vector4f v1) 215 | { 216 | double vDot = this.dot(v1) / ( this.length()*v1.length() ); 217 | if( vDot < -1.0) vDot = -1.0; 218 | if( vDot > 1.0) vDot = 1.0; 219 | return((float) (Math.acos( vDot ))); 220 | } 221 | 222 | } 223 | -------------------------------------------------------------------------------- /src/javax/vecmath/Vector4d.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 4-element vector represented by double-precision floating point 32 | * x,y,z,w coordinates. 33 | * 34 | */ 35 | public class Vector4d extends Tuple4d implements java.io.Serializable { 36 | 37 | // Compatible with 1.1 38 | static final long serialVersionUID = 3938123424117448700L; 39 | 40 | /** 41 | * Constructs and initializes a Vector4d from the specified xyzw coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | * @param z the z coordinate 45 | * @param w the w coordinate 46 | */ 47 | public Vector4d(double x, double y, double z, double w) 48 | { 49 | super(x,y,z,w); 50 | } 51 | 52 | /** 53 | * Constructs and initializes a Vector4d from the coordinates contained 54 | * in the array. 55 | * @param v the array of length 4 containing xyzw in order 56 | */ 57 | public Vector4d(double[] v) 58 | { 59 | super(v); 60 | } 61 | 62 | /** 63 | * Constructs and initializes a Vector4d from the specified Vector4d. 64 | * @param v1 the Vector4d containing the initialization x y z w data 65 | */ 66 | public Vector4d(Vector4d v1) 67 | { 68 | super(v1); 69 | } 70 | 71 | /** 72 | * Constructs and initializes a Vector4d from the specified Vector4f. 73 | * @param v1 the Vector4f containing the initialization x y z w data 74 | */ 75 | public Vector4d(Vector4f v1) 76 | { 77 | super(v1); 78 | } 79 | 80 | /** 81 | * Constructs and initializes a Vector4d from the specified Tuple4f. 82 | * @param t1 the Tuple4f containing the initialization x y z w data 83 | */ 84 | public Vector4d(Tuple4f t1) 85 | { 86 | super(t1); 87 | } 88 | 89 | /** 90 | * Constructs and initializes a Vector4d from the specified Tuple4d. 91 | * @param t1 the Tuple4d containing the initialization x y z w data 92 | */ 93 | public Vector4d(Tuple4d t1) 94 | { 95 | super(t1); 96 | } 97 | 98 | 99 | /** 100 | * Constructs and initializes a Vector4d from the specified Tuple3d. 101 | * The x,y,z components of this vector are set to the corresponding 102 | * components of tuple t1. The w component of this vector 103 | * is set to 0. 104 | * @param t1 the tuple to be copied 105 | * 106 | * @since vecmath 1.2 107 | */ 108 | public Vector4d(Tuple3d t1) { 109 | super(t1.x, t1.y, t1.z, 0.0); 110 | } 111 | 112 | 113 | /** 114 | * Constructs and initializes a Vector4d to (0,0,0,0). 115 | */ 116 | public Vector4d() 117 | { 118 | super(); 119 | } 120 | 121 | 122 | /** 123 | * Sets the x,y,z components of this vector to the corresponding 124 | * components of tuple t1. The w component of this vector 125 | * is set to 0. 126 | * @param t1 the tuple to be copied 127 | * 128 | * @since vecmath 1.2 129 | */ 130 | public final void set(Tuple3d t1) { 131 | this.x = t1.x; 132 | this.y = t1.y; 133 | this.z = t1.z; 134 | this.w = 0.0; 135 | } 136 | 137 | 138 | /** 139 | * Returns the length of this vector. 140 | * @return the length of this vector 141 | */ 142 | public final double length() 143 | { 144 | return Math.sqrt(this.x*this.x + this.y*this.y + 145 | this.z*this.z + this.w*this.w); 146 | } 147 | 148 | 149 | /** 150 | * Returns the squared length of this vector. 151 | * @return the squared length of this vector 152 | */ 153 | public final double lengthSquared() 154 | { 155 | return (this.x*this.x + this.y*this.y + 156 | this.z*this.z + this.w*this.w); 157 | } 158 | 159 | 160 | /** 161 | * Returns the dot product of this vector and vector v1. 162 | * @param v1 the other vector 163 | * @return the dot product of this vector and vector v1 164 | */ 165 | public final double dot(Vector4d v1) 166 | { 167 | return (this.x*v1.x + this.y*v1.y + this.z*v1.z + this.w*v1.w); 168 | } 169 | 170 | 171 | /** 172 | * Sets the value of this vector to the normalization of vector v1. 173 | * @param v1 the un-normalized vector 174 | */ 175 | public final void normalize(Vector4d v1) 176 | { 177 | double norm; 178 | 179 | norm = 1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z + v1.w*v1.w); 180 | this.x = v1.x*norm; 181 | this.y = v1.y*norm; 182 | this.z = v1.z*norm; 183 | this.w = v1.w*norm; 184 | } 185 | 186 | 187 | /** 188 | * Normalizes this vector in place. 189 | */ 190 | public final void normalize() 191 | { 192 | double norm; 193 | 194 | norm = 1.0/Math.sqrt(this.x*this.x + this.y*this.y + 195 | this.z*this.z + this.w*this.w); 196 | this.x *= norm; 197 | this.y *= norm; 198 | this.z *= norm; 199 | this.w *= norm; 200 | } 201 | 202 | 203 | /** 204 | * Returns the (4-space) angle in radians between this vector and 205 | * the vector parameter; the return value is constrained to the 206 | * range [0,PI]. 207 | * @param v1 the other vector 208 | * @return the angle in radians in the range [0,PI] 209 | */ 210 | public final double angle(Vector4d v1) 211 | { 212 | double vDot = this.dot(v1) / ( this.length()*v1.length() ); 213 | if( vDot < -1.0) vDot = -1.0; 214 | if( vDot > 1.0) vDot = 1.0; 215 | return((double) (Math.acos( vDot ))); 216 | } 217 | 218 | } 219 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point4f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 4 element point represented by single precision floating point x,y,z,w 32 | * coordinates. 33 | * 34 | */ 35 | public class Point4f extends Tuple4f implements java.io.Serializable { 36 | 37 | 38 | // Compatible with 1.1 39 | static final long serialVersionUID = 4643134103185764459L; 40 | 41 | /** 42 | * Constructs and initializes a Point4f from the specified xyzw coordinates. 43 | * @param x the x coordinate 44 | * @param y the y coordinate 45 | * @param z the z coordinate 46 | * @param w the w coordinate 47 | */ 48 | public Point4f(float x, float y, float z, float w) 49 | { 50 | super(x,y,z,w); 51 | } 52 | 53 | 54 | /** 55 | * Constructs and initializes a Point4f from the array of length 4. 56 | * @param p the array of length 4 containing xyzw in order 57 | */ 58 | public Point4f(float[] p) 59 | { 60 | super(p); 61 | } 62 | 63 | 64 | /** 65 | * Constructs and initializes a Point4f from the specified Point4f. 66 | * @param p1 the Point4f containing the initialization x y z w data 67 | */ 68 | public Point4f(Point4f p1) 69 | { 70 | super(p1); 71 | } 72 | 73 | 74 | /** 75 | * Constructs and initializes a Point4f from the specified Point4d. 76 | * @param p1 the Point4d containing the initialization x y z w data 77 | */ 78 | public Point4f(Point4d p1) 79 | { 80 | super(p1); 81 | } 82 | 83 | 84 | /** 85 | * Constructs and initializes a Point4f from the specified Tuple4f. 86 | * @param t1 the Tuple4f containing the initialization x y z w data 87 | */ 88 | public Point4f(Tuple4f t1) 89 | { 90 | super(t1); 91 | } 92 | 93 | 94 | /** 95 | * Constructs and initializes a Point4f from the specified Tuple4d. 96 | * @param t1 the Tuple4d containing the initialization x y z w data 97 | */ 98 | public Point4f(Tuple4d t1) 99 | { 100 | super(t1); 101 | } 102 | 103 | 104 | /** 105 | * Constructs and initializes a Point4f from the specified Tuple3f. 106 | * The x,y,z components of this point are set to the corresponding 107 | * components of tuple t1. The w component of this point 108 | * is set to 1. 109 | * @param t1 the tuple to be copied 110 | * 111 | * @since vecmath 1.2 112 | */ 113 | public Point4f(Tuple3f t1) { 114 | super(t1.x, t1.y, t1.z, 1.0f); 115 | } 116 | 117 | 118 | /** 119 | * Constructs and initializes a Point4f to (0,0,0,0). 120 | */ 121 | public Point4f() 122 | { 123 | super(); 124 | } 125 | 126 | 127 | /** 128 | * Sets the x,y,z components of this point to the corresponding 129 | * components of tuple t1. The w component of this point 130 | * is set to 1. 131 | * @param t1 the tuple to be copied 132 | * 133 | * @since vecmath 1.2 134 | */ 135 | public final void set(Tuple3f t1) { 136 | this.x = t1.x; 137 | this.y = t1.y; 138 | this.z = t1.z; 139 | this.w = 1.0f; 140 | } 141 | 142 | 143 | /** 144 | * Computes the square of the distance between this point and point p1. 145 | * @param p1 the other point 146 | * @return the square of distance between these two points as a float 147 | */ 148 | public final float distanceSquared(Point4f p1) 149 | { 150 | float dx, dy, dz, dw; 151 | 152 | dx = this.x-p1.x; 153 | dy = this.y-p1.y; 154 | dz = this.z-p1.z; 155 | dw = this.w-p1.w; 156 | return (dx*dx+dy*dy+dz*dz+dw*dw); 157 | } 158 | 159 | 160 | /** 161 | * Computes the distance between this point and point p1. 162 | * @param p1 the other point 163 | * @return the distance between the two points 164 | */ 165 | public final float distance(Point4f p1) 166 | { 167 | float dx, dy, dz, dw; 168 | 169 | dx = this.x-p1.x; 170 | dy = this.y-p1.y; 171 | dz = this.z-p1.z; 172 | dw = this.w-p1.w; 173 | return (float) Math.sqrt(dx*dx+dy*dy+dz*dz+dw*dw); 174 | } 175 | 176 | 177 | /** 178 | * Computes the L-1 (Manhattan) distance between this point and 179 | * point p1. The L-1 distance is equal to: 180 | * abs(x1-x2) + abs(y1-y2) + abs(z1-z2) + abs(w1-w2). 181 | * @param p1 the other point 182 | * @return the L-1 distance 183 | */ 184 | public final float distanceL1(Point4f p1) 185 | { 186 | return( Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) + Math.abs(this.z-p1.z) + Math.abs(this.w-p1.w)); 187 | } 188 | 189 | 190 | /** 191 | * Computes the L-infinite distance between this point and 192 | * point p1. The L-infinite distance is equal to 193 | * MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2), abs(w1-w2)]. 194 | * @param p1 the other point 195 | * @return the L-infinite distance 196 | */ 197 | public final float distanceLinf(Point4f p1) 198 | { 199 | float t1, t2; 200 | t1 = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y)); 201 | t2 = Math.max( Math.abs(this.z-p1.z), Math.abs(this.w-p1.w)); 202 | 203 | return(Math.max(t1,t2)); 204 | 205 | } 206 | 207 | /** 208 | * Multiplies each of the x,y,z components of the Point4f parameter 209 | * by 1/w, places the projected values into this point, and places 210 | * a 1 as the w parameter of this point. 211 | * @param p1 the source Point4f, which is not modified 212 | */ 213 | public final void project(Point4f p1) 214 | { 215 | float oneOw; 216 | 217 | oneOw = 1/p1.w; 218 | x = p1.x*oneOw; 219 | y = p1.y*oneOw; 220 | z = p1.z*oneOw; 221 | w = 1.0f; 222 | 223 | } 224 | 225 | } 226 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point4d.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 4 element vector represented by double precision floating point 32 | * x,y,z,w coordinates. 33 | * 34 | */ 35 | public class Point4d extends Tuple4d implements java.io.Serializable { 36 | 37 | // Compatible with 1.1 38 | static final long serialVersionUID = 1733471895962736949L; 39 | 40 | 41 | /** 42 | * Constructs and initializes a Point4d from the specified xyzw coordinates. 43 | * @param x the x coordinate 44 | * @param y the y coordinate 45 | * @param z the z coordinate 46 | * @param w the w coordinate 47 | */ 48 | public Point4d(double x, double y, double z, double w) 49 | { 50 | super(x,y,z,w); 51 | } 52 | 53 | /** 54 | * Constructs and initializes a Point4d from the coordinates contained 55 | * in the array. 56 | * @param p the array of length 4 containing xyzw in order 57 | */ 58 | public Point4d(double[] p) 59 | { 60 | super(p); 61 | } 62 | 63 | 64 | /** 65 | * Constructs and initializes a Point4d from the specified Point4d. 66 | * @param p1 the Point4d containing the initialization x y z w data 67 | */ 68 | public Point4d(Point4d p1) 69 | { 70 | super(p1); 71 | } 72 | 73 | 74 | /** 75 | * Constructs and initializes a Point4d from the specified Point4f. 76 | * @param p1 the Point4f containing the initialization x y z w data 77 | */ 78 | public Point4d(Point4f p1) 79 | { 80 | super(p1); 81 | } 82 | 83 | 84 | /** 85 | * Constructs and initializes a Point4d from the specified Tuple4f. 86 | * @param t1 the Tuple4f containing the initialization x y z w data 87 | */ 88 | public Point4d(Tuple4f t1) 89 | { 90 | super(t1); 91 | } 92 | 93 | 94 | /** 95 | * Constructs and initializes a Point4d from the specified Tuple4d. 96 | * @param t1 the Tuple4d containing the initialization x y z w data 97 | */ 98 | public Point4d(Tuple4d t1) 99 | { 100 | super(t1); 101 | } 102 | 103 | 104 | /** 105 | * Constructs and initializes a Point4d from the specified Tuple3d. 106 | * The x,y,z components of this point are set to the corresponding 107 | * components of tuple t1. The w component of this point 108 | * is set to 1. 109 | * @param t1 the tuple to be copied 110 | * 111 | * @since vecmath 1.2 112 | */ 113 | public Point4d(Tuple3d t1) { 114 | super(t1.x, t1.y, t1.z, 1.0); 115 | } 116 | 117 | 118 | /** 119 | * Constructs and initializes a Point4d to (0,0,0,0). 120 | */ 121 | public Point4d() 122 | { 123 | super(); 124 | } 125 | 126 | 127 | /** 128 | * Sets the x,y,z components of this point to the corresponding 129 | * components of tuple t1. The w component of this point 130 | * is set to 1. 131 | * @param t1 the tuple to be copied 132 | * 133 | * @since vecmath 1.2 134 | */ 135 | public final void set(Tuple3d t1) { 136 | this.x = t1.x; 137 | this.y = t1.y; 138 | this.z = t1.z; 139 | this.w = 1.0; 140 | } 141 | 142 | 143 | /** 144 | * Returns the square of the distance between this point and point p1. 145 | * @param p1 the first point 146 | * @return the square of distance between this point and point p1 147 | */ 148 | public final double distanceSquared(Point4d p1) 149 | { 150 | double dx, dy, dz, dw; 151 | 152 | dx = this.x-p1.x; 153 | dy = this.y-p1.y; 154 | dz = this.z-p1.z; 155 | dw = this.w-p1.w; 156 | return (dx*dx+dy*dy+dz*dz+dw*dw); 157 | } 158 | 159 | 160 | /** 161 | * Returns the distance between this point and point p1. 162 | * @param p1 the first point 163 | * @return the distance between these this point and point p1. 164 | */ 165 | public final double distance(Point4d p1) 166 | { 167 | double dx, dy, dz, dw; 168 | 169 | dx = this.x-p1.x; 170 | dy = this.y-p1.y; 171 | dz = this.z-p1.z; 172 | dw = this.w-p1.w; 173 | return Math.sqrt(dx*dx+dy*dy+dz*dz+dw*dw); 174 | } 175 | 176 | 177 | /** 178 | * Computes the L-1 (Manhattan) distance between this point and 179 | * point p1. The L-1 distance is equal to: 180 | * abs(x1-x2) + abs(y1-y2) + abs(z1-z2) + abs(w1-w2). 181 | * @param p1 the other point 182 | * @return the L-1 distance 183 | */ 184 | public final double distanceL1(Point4d p1) { 185 | return Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) + 186 | Math.abs(this.z-p1.z) + Math.abs(this.w-p1.w); 187 | } 188 | 189 | /** 190 | * Computes the L-infinite distance between this point and 191 | * point p1. The L-infinite distance is equal to 192 | * MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2), abs(w1-w2)]. 193 | * @param p1 the other point 194 | * @return the L-infinite distance 195 | */ 196 | public final double distanceLinf(Point4d p1) { 197 | double t1, t2; 198 | t1 = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y)); 199 | t2 = Math.max( Math.abs(this.z-p1.z), Math.abs(this.w-p1.w)); 200 | 201 | return Math.max(t1,t2); 202 | } 203 | 204 | /** 205 | * Multiplies each of the x,y,z components of the Point4d parameter 206 | * by 1/w, places the projected values into this point, and places 207 | * a 1 as the w parameter of this point. 208 | * @param p1 the source Point4d, which is not modified 209 | */ 210 | public final void project(Point4d p1) 211 | { 212 | double oneOw; 213 | 214 | oneOw = 1/p1.w; 215 | x = p1.x*oneOw; 216 | y = p1.y*oneOw; 217 | z = p1.z*oneOw; 218 | w = 1.0; 219 | 220 | } 221 | 222 | 223 | } 224 | -------------------------------------------------------------------------------- /src/javax/vecmath/Tuple3b.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A three byte tuple. Note that Java defines a byte as a signed integer 32 | * in the range [-128, 127]. However, colors are more typically 33 | * represented by values in the range [0, 255]. Java 3D recognizes this 34 | * and, in those cases where Tuple3b is used to represent color, treats 35 | * the bytes as if the range were [0, 255]---in other words, as if the 36 | * bytes were unsigned. 37 | * Values greater than 127 can be assigned to a byte variable using a 38 | * type cast. For example: 39 | *