Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12125/src/net/sourceforge/bprocessor/model
Added Files:
CoordinateSystem.java
Log Message:
Added the CoordinateSystem class
--- NEW FILE: CoordinateSystem.java ---
//---------------------------------------------------------------------------------
// $Id: CoordinateSystem.java,v 1.1 2005/09/01 12:17:16 henryml Exp $
//
// Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net)
// Released under the Lesser GNU Public License v2.1
//---------------------------------------------------------------------------------
package net.sourceforge.bprocessor.model;
/**
* The CoordinateSystem is represented by
* three orthogonal unit vectors, i, j and n.
* i, and j represents the xy-plane of the
* coordinate system and n is a normal vector
* to that plane.
* The origin places the CoordinateSystem relative
* to the global coordinate system.
*/
public class CoordinateSystem {
/** The i unit vector (x-direction) */
protected Vertex i;
/** The j unit vector (y-direction) */
protected Vertex j;
/** The n unit vector (z-direction) */
protected Vertex n;
/** The origin of the coordinate system */
protected Vertex origin;
/**
* Constructor
* @param i The i vector
* @param j The j vector
* @param n The n vector
* @param origin The origin
*/
public CoordinateSystem(Vertex i, Vertex j, Vertex n, Vertex origin) {
super();
this.i = i;
this.j = j;
this.n = n;
this.origin = origin;
}
/**
* Returns the projection of vector on z-axis (n vector)
* @param vector The vector to project on z
* @return The projectet vector
*/
public Vertex perpendicular(Vertex vector) {
Vertex projection = new Vertex("n projection of vector");
projection.setX(n.getX());
projection.setY(n.getY());
projection.setZ(n.getZ());
double scalar = n.dot(vector);
projection.scale(scalar);
return projection;
}
/**
* Returns the projection of vector on the xy-plane
* @param vector The vector to project
* @return The projected vector
*/
public Vertex projection(Vertex vector) {
Vertex p = perpendicular(vector);
return vector.minus(p);
}
/**
* Return the vertex translated to this CoordinateSystem
* @param vertex The vertex to translate
* @return The translated vertex
*/
public Vertex translate(Vertex vertex) {
Vertex v = vertex.minus(origin);
double x = i.dot(v);
double y = j.dot(v);
double z = n.dot(v);
v.setX(x);
v.setY(y);
v.setZ(z);
return v;
}
}
|