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