]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGMatrix.cpp
builddir -> srcdir so builds can be done outside the master source directory.
[flightgear.git] / src / FDM / JSBSim / FGMatrix.cpp
index c7f40c4b7f659163d3618bdf2b7d80f7e7d2e822..5b4f5da10ba5937b5f0495d92a53517c19144544 100644 (file)
@@ -337,23 +337,31 @@ FGMatrix FGMatrix::operator/(const double scalar)
 {
   FGMatrix Quot(Rows(), Cols());
 
-  for (unsigned int i=1; i<=Rows(); i++) {
-    for (unsigned int j=1; j<=Cols(); j++)  {
-       Quot(i,j) = data[i][j]/scalar;
+  if(scalar != 0) {
+    for (unsigned int i=1; i<=Rows(); i++) {
+      for (unsigned int j=1; j<=Cols(); j++)  {
+         Quot(i,j) = data[i][j]/scalar;
+      }
     }
-  }
-  return Quot;
+    
+  } else
+    cerr << "Attempt to divide by zero in method FGMatrix::operator/(const double scalar), object at " << this << endl; 
+  return Quot;  
 }
 
 /******************************************************************************/
 
 void FGMatrix::operator/=(const double scalar)
 {
-  for (unsigned int i=1; i<=Rows(); i++)  {
-    for (unsigned int j=1; j<=Cols(); j++) {
-      data[i][j]/=scalar;
+  
+  if(scalar != 0) {
+    for (unsigned int i=1; i<=Rows(); i++)  {
+      for (unsigned int j=1; j<=Cols(); j++) {
+        data[i][j]/=scalar;
+      }
     }
-  }
+  } else 
+    cerr << "Attempt to divide by zero in method FGMatrix::operator/=(const double scalar), object " << this << endl; 
 }
 
 /******************************************************************************/
@@ -512,10 +520,16 @@ FGColumnVector FGColumnVector::operator-(const FGColumnVector& V)
 FGColumnVector FGColumnVector::operator/(const double scalar)
 {
   FGColumnVector Quotient(Rows());
+  if(scalar != 0) {
+    
 
-  for (unsigned int i=1; i<=Rows(); i++) Quotient(i) = data[i][1] / scalar;
+    for (unsigned int i=1; i<=Rows(); i++) Quotient(i) = data[i][1] / scalar;
 
+  } else 
+    cerr << "Attempt to divide by zero in method FGColumnVector::operator/(const double scalar), object " << this << endl; 
   return Quotient;
+  
+    
 }
 
 /******************************************************************************/
@@ -554,9 +568,11 @@ FGColumnVector FGColumnVector::Normalize(void)
 {
   double Mag = Magnitude();
 
-  for (unsigned int i=1; i<=Rows(); i++)
-    for (unsigned int j=1; j<=Cols(); j++)
-      data[i][j] = data[i][j]/Mag;
+  if (Mag != 0) {
+    for (unsigned int i=1; i<=Rows(); i++)
+      for (unsigned int j=1; j<=Cols(); j++)
+        data[i][j] = data[i][j]/Mag;
+  }    
 
   return *this;
 }
@@ -582,3 +598,21 @@ FGColumnVector FGColumnVector::operator*(const FGColumnVector& V)
 
 /******************************************************************************/
 
+FGColumnVector FGColumnVector::multElementWise(const FGColumnVector& V)
+{
+  if (Rows() != 3 || V.Rows() != 3) {
+    MatrixException mE;
+    mE.Message = "Invalid row count in vector cross product function";
+    throw mE;
+  }
+
+  FGColumnVector Product(3);
+
+  Product(1) = data[1][1] * V(1);
+  Product(2) = data[2][1] * V(2);
+  Product(3) = data[3][1] * V(3);
+
+  return Product;
+}
+
+/******************************************************************************/