001 /*
002 * $Id: MathUtils.java,v 1.5 2012/02/19 17:35:39 davep Exp $
003 *
004 * This file is part of McIDAS-V
005 *
006 * Copyright 2007-2012
007 * Space Science and Engineering Center (SSEC)
008 * University of Wisconsin - Madison
009 * 1225 W. Dayton Street, Madison, WI 53706, USA
010 * https://www.ssec.wisc.edu/mcidas
011 *
012 * All Rights Reserved
013 *
014 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015 * some McIDAS-V source code is based on IDV and VisAD source code.
016 *
017 * McIDAS-V is free software; you can redistribute it and/or modify
018 * it under the terms of the GNU Lesser Public License as published by
019 * the Free Software Foundation; either version 3 of the License, or
020 * (at your option) any later version.
021 *
022 * McIDAS-V is distributed in the hope that it will be useful,
023 * but WITHOUT ANY WARRANTY; without even the implied warranty of
024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
025 * GNU Lesser Public License for more details.
026 *
027 * You should have received a copy of the GNU Lesser Public License
028 * along with this program. If not, see http://www.gnu.org/licenses.
029 */
030 // Shawn E. Gano
031 /**
032 * =====================================================================
033 * Copyright (C) 2009 Shawn E. Gano
034 *
035 * This file is part of JSatTrak.
036 *
037 * JSatTrak is free software: you can redistribute it and/or modify
038 * it under the terms of the GNU Lesser General Public License as published by
039 * the Free Software Foundation, either version 3 of the License, or
040 * (at your option) any later version.
041 *
042 * JSatTrak is distributed in the hope that it will be useful,
043 * but WITHOUT ANY WARRANTY; without even the implied warranty of
044 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
045 * GNU Lesser General Public License for more details.
046 *
047 * You should have received a copy of the GNU Lesser General Public License
048 * along with JSatTrak. If not, see <http://www.gnu.org/licenses/>.
049 * =====================================================================
050 */
051
052 package edu.wisc.ssec.mcidasv.data.adde.sgp4;
053
054 /**
055 * Various Math functions; many of them for vector and matrix operations for 3 dimensions.
056 */
057 public class MathUtils
058 {
059
060 // vector 2-norm
061 /**
062 * vector 2-norm
063 *
064 * @param a vector of length 3
065 * @return norm(a)
066 */
067 public static double norm(double[] a)
068 {
069 double c = 0.0;
070
071 for(int i=0;i<a.length;i++)
072 {
073 c += a[i]*a[i];
074 }
075
076 return Math.sqrt(c);
077 }
078
079 // dot product for 3D vectors
080 /**
081 * dot product for 3D vectors
082 *
083 * @param a 3x1 vector
084 * @param b 3x1 vector
085 * @return a dot b
086 */
087 public static double dot(double[] a, double[] b)
088 {
089 double c =0;;
090
091 for (int i = 0; i < 3; i++) // row
092 {
093 c += a[i]*b[i];
094 }
095
096 return c;
097
098 } // mult 3x3 matrices
099
100 /**
101 * multiply two matrices 3x3
102 *
103 * @param a 3x3 matrix
104 * @param b 3x3 matrix
105 * @return a x b
106 */
107 public static double[][] mult(double[][] a, double[][] b)
108 {
109 double[][] c = new double[3][3];
110
111 for (int i = 0; i < 3; i++) // row
112 {
113 for (int j = 0; j < 3; j++) // col
114 {
115 c[i][j] = 0.0;
116 for (int k = 0; k < 3; k++)
117 {
118 c[i][j] += a[i][k] * b[k][j];
119 }
120 }
121 }
122
123 return c;
124
125 } // mult 3x3 matrices
126
127 /**
128 * vector subtraction
129 *
130 * @param a vector of length 3
131 * @param b vector of length 3
132 * @return a-b
133 */
134 public static double[] sub(double[] a, double[] b)
135 {
136 double[] c = new double[3];
137 for(int i=0;i<3;i++)
138 {
139 c[i] = a[i] - b[i];
140 }
141
142 return c;
143 }
144 }