/* Class VectorMaths
*
* Defines a vector and includes the methods needed
* for standard vector manipulations, e.g. addition,
* dot product, cross product and related procedures.
*
* WRITTEN BY: Dr Michael Thomas Flanagan
*
* DATE: November - December 2011
* UPDATES: 5 December 2011
*
* DOCUMENTATION:
* See Michael Thomas Flanagan's Java library on-line web page:
* http://www.ee.ucl.ac.uk/~mflanaga/java/VectorMaths.html
* http://www.ee.ucl.ac.uk/~mflanaga/java/
*
* Copyright (c) 2011 Michael Thomas Flanagan
* PERMISSION TO COPY:
*
* Permission to use, copy and modify this software and its documentation for NON-COMMERCIAL purposes is granted, without fee,
* provided that an acknowledgement to the author, Dr Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies
* and associated documentation or publications.
*
* Redistributions of the source code of this source code, or parts of the source codes, must retain the above copyright notice, this list of conditions
* and the following disclaimer and requires written permission from the Michael Thomas Flanagan:
*
* Redistribution in binary form of all or parts of this class must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution and requires written permission from the Michael Thomas Flanagan:
*
* Dr Michael Thomas Flanagan makes no representations about the suitability or fitness of the software for any or for a particular purpose.
* Dr Michael Thomas Flanagan shall not be liable for any damages suffered as a result of using, modifying or distributing this software
* or its derivatives.
*
***************************************************************************************/
package flanagan.math;
import flanagan.circuits.Phasor;
public class VectorMaths{
Point point0 = null; // origin coordinates
Point point1 = null; // final coordinates
int nDimensionsEntered = 0; // dimensions of the cartesian space
// CONSTRUCTORS
// final point coordinates provided as array
// initial point - cartesian origin
public VectorMaths(double[] coord){
this.setVector(coord);
}
// coordinates provided as array
// coord0 = initial point, coord1 = final point
public VectorMaths(double[] coord0, double[] coord1){
this.setVector(coord0, coord1);
}
// final coordinates provided as x, y and z values
// initial point - cartesian origin
public VectorMaths(double xPoint, double yPoint, double zPoint){
this.setVector(xPoint, yPoint, zPoint);
}
// final coordinates provided as x and y values (z set to 0.0)
// initial point - cartesian origin
public VectorMaths(double xPoint, double yPoint){
this.setVector(xPoint, yPoint);
}
// final coordinates provided as x value (y and z set to 0.0)
// initial point - cartesian origin
public VectorMaths(double xPoint){
this.setVector(xPoint);
}
// final coordinates provided as a Point
// initial point - cartesian origin
public VectorMaths(Point point1){
this.setVector(point1);
}
// coordinates provided as Point
// initial point - point0, final point - point1
public VectorMaths(Point point0, Point point1){
this.setVector(point0, point1);
}
// SET VECTOR COORDINATES
// coordinates provided as array
// initial point - cartesian origin
public void setVector(double[] coord){
this.nDimensionsEntered = coord.length;
if(this.nDimensionsEntered>3)throw new IllegalArgumentException("VectorMaths will not handle dimensional spaces greater than 3-dimensional");
double[] ccc1 = new double[3];
for(int i=0; i3)throw new IllegalArgumentException("VectorMaths will not handle dimensional spaces greater than 3-dimensional");
double[] ccc0 = new double[3];
double[] ccc1 = new double[3];
for(int i=0; i3)throw new IllegalArgumentException("VectorMaths will not handle dimensional spaces greater than 3-dimensional");
this.nDimensionsEntered = n;
if(n==3){
this.point1 = point1;
}
else{
double[] ccc0 = point1.getPointCoordinates();
double[] ccc1 = new double[3];
for(int i=0; i3)throw new IllegalArgumentException("VectorMaths will not handle dimensional spaces greater than 3-dimensional");
if(n==3){
this.point0 = point0.copy();
this.point1 = point1.copy();
}
else{
double[] cccc0 = point0.getPointCoordinates();
double[] cccc1 = point1.getPointCoordinates();
double[] ccc0 = new double[3];
double[] ccc1 = new double[3];
for(int i=0; i
Ads help maintain this website.