Back to project page zmap.
The source code is released under:
GNU Lesser General Public License
If you think the Android project zmap listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.zmap.geom; //from w ww. j a v a2 s. c o m public class Vector implements IVector { public Vector() { vector = new double[3]; } public Vector(double x, double y, double z) { this(); setX(x); setY(y); setZ(z); } /** * @note Instantiate a vector pointed from a to b. */ public Vector(IPoint from, IPoint to) { this(); if(from == null || to == null) { throw new NullPointerException(); } if(from.isEmpty() || to.isEmpty()) { throw new EmptyGeometryException(); } setX(to.getX() - from.getX()); setY(to.getY() - from.getY()); setZ(to.getZ() - from.getZ()); } @Override public double getX() { return vector[X_INDEX]; } @Override public double getY() { return vector[Y_INDEX]; } @Override public double getZ() { return vector[Z_INDEX]; } @Override public double[] get() { return vector; } @Override public void setX(double x) { vector[X_INDEX] = x; } @Override public void setY(double y) { vector[Y_INDEX] = y; } @Override public void setZ(double z) { vector[Z_INDEX] = z; } @Override public void set(double[] v) { vector[X_INDEX] = v[X_INDEX]; vector[Y_INDEX] = v[Y_INDEX]; vector[Z_INDEX] = v[Z_INDEX]; } @Override public IVector crossProduct(IVector w) { if(w == null) { throw new NullPointerException(); } double vx = getX(); double vy = getY(); double vz = getZ(); double wx = w.getX(); double wy = w.getY(); double wz = w.getZ(); IVector p = new Vector(); p.setX(vy * wz - vz * wy); p.setY(vz * wx - vx * wz); p.setZ(vx * wy - vy * wx); return p; } public double dotProduct(IVector w) { if(w == null) { throw new NullPointerException(); } double d = getX() * w.getX() + getY() * w.getY() + getZ() * w.getZ(); return d; } public double norm() { return Math.sqrt(getX() * getX() + getY() * getY() + getZ() * getZ()); } private double[] vector; private static final int X_INDEX = 0; private static final int Y_INDEX = 1; private static final int Z_INDEX = 2; }