entanglement 17 de nov. de 2009
OCTAVIO 19 de nov. de 2009
Putz entanglement, baixei as classes do site, só que dá vários erros.
Acredito que estejam faltando as biliotecas.
Vc sabe onde eu consigo as biliotecas?
pablosaraiva 19 de nov. de 2009
Rapaz… tenho quase tudo isso.
Vê se te ajuda.
public class Matrix3D {
public double [][] a = new double [ 3 ][ 3 ] ;
Matrix3D () {};
Matrix3D ( double [][] b ) {
for ( int i = 0 ; i < 3 ; i ++ ) {
for ( int j = 0 ; j < 3 ; j ++ ) {
this . a [ i ][ j ] = b [ i ][ j ] ;
}
}
};
public void inverteLinha ( int linhaA , int linhaB ) {
double temp ;
for ( int i = 0 ; i < 3 ; i ++ ) {
temp = this . a [ linhaA ][ i ] ;
this . a [ linhaA ][ i ] = this . a [ linhaB ][ i ] ;
this . a [ linhaB ][ i ] = temp ;
}
}
public void setIdentity () {
for ( int i = 0 ; i < 3 ; i ++ ) {
for ( int j = 0 ; j < 3 ; j ++ ) {
if ( i == j ) {
this . a [ i ][ j ] = 1 ;
}
else {
this . a [ i ][ j ] = 0 ;
}
}
}
}
public Matrix3D matrixAdd ( Matrix3D B ) {
Matrix3D C = new Matrix3D ();
for ( int i = 0 ; i < 3 ; i ++ ) {
for ( int j = 0 ; j < 3 ; j ++ ) {
C . a [ i ][ j ] = this . a [ i ][ j ] + B . a [ i ][ j ] ;
}
}
return ( C );
}
public Matrix3D matrixSub ( Matrix3D B ) {
Matrix3D C = new Matrix3D ();
for ( int i = 0 ; i < 3 ; i ++ ) {
for ( int j = 0 ; j < 3 ; j ++ ) {
C . a [ i ][ j ] = this . a [ i ][ j ] - B . a [ i ][ j ] ;
}
}
return ( C );
}
public Matrix3D matrixMulti ( Matrix3D B ) {
Matrix3D C = new Matrix3D ();
for ( int i = 0 ; i < 3 ; i ++ ) {
for ( int j = 0 ; j < 3 ; j ++ ) {
C . a [ i ][ j ] = this . a [ i ][ 0 ] * B . a [ 0 ][ j ] + this . a [ i ][ 1 ] * B . a [ 1 ][ j ] + this . a [ i ][ 2 ] * B . a [ 2 ][ j ] ;
}
}
return ( C );
}
public Vector3D vectorMulti ( Vector3D B ) {
Vector3D C = new Vector3D ();
C . setX ( this . a [ 0 ][ 0 ]* B . getX () + this . a [ 0 ][ 1 ]* B . getY () + this . a [ 0 ][ 2 ]* B . getZ ());
C . setY ( this . a [ 1 ][ 0 ]* B . getX () + this . a [ 1 ][ 1 ]* B . getY () + this . a [ 1 ][ 2 ]* B . getZ ());
C . setZ ( this . a [ 2 ][ 0 ]* B . getX () + this . a [ 2 ][ 1 ]* B . getY () + this . a [ 2 ][ 2 ]* B . getZ ());
return ( C );
}
public Matrix3D scalarMult ( double b ) {
Matrix3D C = new Matrix3D ();
for ( int i = 0 ; i < 3 ; i ++ ) {
for ( int j = 0 ; j < 3 ; j ++ ) {
C . a [ i ][ j ] = this . a [ i ][ j ] * b ;
}
}
return ( C );
}
public Matrix3D scalarDiv ( double b ) {
Matrix3D C = new Matrix3D ();
for ( int i = 0 ; i < 3 ; i ++ ) {
for ( int j = 0 ; j < 3 ; j ++ ) {
C . a [ i ][ j ] = this . a [ i ][ j ] / b ;
}
}
return ( C );
}
public double getDeterminant () {
double retorno = 0 ;
for ( int i = 0 ; i < 3 ; i ++ ) {
double elem = 1 ;
int k = i ;
for ( int j = 0 ; j < 3 ; j ++ ) {
elem = elem * this . a [ j ][ k ] ;
k ++ ;
if ( k == 3 ) {
k = 0 ;
}
}
retorno += elem ;
}
for ( int i = 2 ; i >= 0 ; i -- ) {
double elem = 1 ;
int k = i ;
for ( int j = 0 ; j < 3 ; j ++ ) {
elem = elem * this . a [ j ][ k ] ;
k -- ;
if ( k == - 1 ) {
k = 2 ;
}
}
retorno -= elem ;
}
return ( retorno );
}
public Matrix3D getInverse () {
Matrix3D B = new Matrix3D ();
B . setIdentity ();
Matrix3D C = new Matrix3D ( this . a );
for ( int j = 0 ; j < 3 ; j ++ ) {
int i = j ;
for ( int a = j ; a < 3 ; a ++ ) {
if ( C . a [ a ][ j ] > C . a [ i ][ j ] ) {
i = a ;
}
}
C . inverteLinha ( i , j );
B . inverteLinha ( i , j );
double m = 1 / C . a [ j ][ j ] ;
for ( int a = 0 ; a < 3 ; a ++ ) {
C . a [ j ][ a ] *= m ;
B . a [ j ][ a ] *= m ;
}
for ( int r = 0 ; r < 3 ; r ++ ) {
if ( r != j ) {
m = - C . a [ r ][ j ] ;
for ( int a = 0 ; a < 3 ; a ++ ) {
C . a [ r ][ a ] += m * C . a [ j ][ a ] ;
B . a [ r ][ a ] += m * B . a [ j ][ a ] ;
}
}
}
}
return ( B );
}
public void show () {
for ( int i = 0 ; i < 3 ; i ++ ) {
for ( int j = 0 ; j < 3 ; j ++ ) {
System . out . print ( this . a [ i ][ j ] );
System . out . print ( "\t" );
}
System . out . println ( "" );
}
}
}
public class Vector3D {
private double x , y , z ;
public void setX ( double x ) {
this . x = x ;
}
public void setY ( double y ) {
this . y = y ;
}
public void setZ ( double z ) {
this . z = z ;
}
public double getX () {
return ( x );
}
public double getY () {
return ( y );
}
public double getZ () {
return ( z );
}
Vector3D () {}
Vector3D ( double x , double y , double z ) {
this . x = x ;
this . y = y ;
this . z = z ;
}
public Vector3D vectorAdd ( Vector3D P ) {
Vector3D result = new Vector3D ( x + P . getX (), y + P . getY (), z + P . getZ ());
return ( result );
}
public Vector3D vectorSub ( Vector3D P ) {
Vector3D result = new Vector3D ( x - P . getX (), y - P . getY (), z - P . getZ ());
return ( result );
}
public Vector3D scalarMult ( double a ) {
Vector3D result = new Vector3D ( x * a , y * a , z * a );
return ( result );
}
public Vector3D scalarDiv ( double a ) {
Vector3D result = new Vector3D ( x / a , y / a , z / a );
return ( result );
}
public double vectorDot ( Vector3D P ) {
double result = x * P . getX () + y * P . getY () + z * P . getZ ();
return ( result );
}
public Vector3D vectorCross ( Vector3D Q ) {
Vector3D result = new Vector3D ( x * Q . getZ () - z * Q . getY (), z * Q . getX () - x * Q . getZ (), x * Q . getY () - y * Q . getX ());
return ( result );
}
public double vectorSize () {
double result = Math . sqrt ( x * x + y * y + z * z );
return ( result );
}
public void show () {
System . out . print ( this . x + "\t" );
System . out . print ( this . y + "\t" );
System . out . println ( this . z );
}
}
pablosaraiva 19 de nov. de 2009
Obviamente vocês vão perceber que os atributos da matriz são públicos.
Isso se dá devido ao fato de ser uma classe que desenvolvi apenas para realizar alguns estudos de matemática. Não estou usando em produção, ainda está em desenvolvimento.
Use como quiser.
Talvez também queira trocar os arrays por alguma Collection. Não recomendo.
OCTAVIO 22 de nov. de 2009
Legal Pablo, deu pra usar mtos metodos que vc colocou ai.
Obrigado cara =))
Abração