All pastes #107917 Raw Edit

Nova Class

public text v1 · immutable
#107917 ·published 2006-07-31 04:51 UTC
rendered paste body
/*
	Vector3D :)
*/

class Vector3D
{
	float x,y,z;
	
	Vector3D ( float x, float y, float z )
	{
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	float[] getCoord ( )
	{
		return { this.x, this.y, this.z };
	}
	
	String toString ( )
	{
		return 	"("+Float.toString(this.x)+","+
					Float.toString(this.y)+","+
					Float.toString(this.z)+")Vector3D";
	}

}

/*
	Math3D :)
*/

class Math3D
{	
	Math3D ( ) 
	{
		// Nothing
	}
	
	float normalize ( Vector3D vector )
	{
		float 	result = Math.sqrt(	( vector.x * vector.x ) + 
									( vector.y * vector.y ) + 
									( vector.z * vector.z )	);
		return	result;
	}
	
	Vector3D addVector ( Vector3D v1, Vector3D v2 )
	{
		Vector3D result = new Vector3D(	( v1.x + v2.x ),
										( v1.y + v2.y ),
										( v1.z + v2.z ) );
		return result;
	}

	Vector3D subVector ( Vector3D v1, Vector3D v2 )
	{
		Vector3D result = new Vector3D(	( v1.x - v2.x ),
										( v1.y - v2.y ),
										( v1.z - v2.z ) );
		return result;
	}
	
	Vector3D scaleMulVector ( Vector3D vector, float scale )
	{
		Vector3D result = new Vector3D(	( vector.x * scale ),
										( vector.y * scale ),
										( vector.z * scale ) );
		return result;
	}
	
	Vector3D scaleDivVector ( Vector3D vector, float scale )
	{
		Vector3D result = new Vector3D(	( vector.x / scale ),
										( vector.y / scale ),
										( vector.z / scale ) );
		return result;
	}
	
	float dotVector ( Vector3D v1, Vector3D v2 )
	{
		float result = ( v1.x * v2.x ) + ( v1.y * v2.y ) + ( v1.z * v2.z );
		return result;
	}
	
	Vector3D crossVector ( Vector3D v1, Vector3D v2 )
	{
		float x,y,z;
		
		x = ( v1.y * v2.z ) - ( v1.z * v2.y );
		//y = ( v1.z * v2.x ) – ( v1.x * v2.z );
		//z = ( v1.x * v2.y ) – ( v1.y * v2.x );
		
		Vector3D result = new Vector3D( x,0.0,0.0 ); 
		
		return result;
	}
	
}