//MathOtter.java //ver.1.12 //安澤出海(泉獺) //なにかと使うMath.class。 //でも、それに足りない機能があるはず。 //というわけで、作ってみました。 /* 【更新履歴】 GALLONtoONS()(ver.1.12) RouleauTriangle()追加。(ver.1.11) GOLD追加。(ver.1.10) TSUBO,TSUBOtoM2(),M2toTSUBO()追加。(ver.1.09) MtoYARD(),YARDtoM(),INCHtoCM(),CMtoINCH()追加。(ver.1.08) KMtoMILE(),MILEtoKM(),MtoFEET(),FEETtoM()追加。(ver.1.07) CtoF(),FtoC()追加。(ver.1.06) */ import java.util.*;//Random public class MathOtter{ public static final int BEAST=666;//黙示録の獣の数字 public static final double FEET=3.28084;//1m public static final double INCH=0.393701;//1cm public static final double MILE=0.62136;//1km public static final double TSUBO=0.30250;//1平方メートル public static final double YARD=1.09361;//1m public static final double GOLD=Math.sqrt(5)/2;//黄金率 //センチをインチに変換。 public static double CMtoINCH(double a){ return a*INCH; } //セ氏を華氏に変換する。 public static double CtoF(double a){ return 5/9*(a-32); } //フィートをメートルに変換。 public static double FEETtoM(double a){ return a/FEET; } //華氏をセ氏に変換する。 public static double FtoC(double a){ return 9/5*a+32; } //ガロンをオンスに変換する。 public static int GALLONtoONS(int a){ return a*32; } //インチをセンチに変換。 public static double INCHtoCM(double a){ return a/INCH; } //キロメートルをマイルに変換。 public static double KMtoMILE(double a){ return a*MILE; } //※華氏911度はおよそセ氏1672度。人間の住める環境ではありません。 //菱形の面積を求める。 /* 菱形の面積を計算して返す。 MathOtter.lozenge(一辺の長さ,一隅の角度※)でその菱形の面積を返す。 尚、数値の型はdouble型とする。int型を希望するなら、返された方で、 (int)Math.round()を用いるなど対応して貰いたい。 ※鋭角・鈍角どちらも可。 */ public static double lozenge(double a,double b){ return Math.sin(Math.toRadians(b))*square(a); } public static double lozenge(int a,double b){ return Math.sin(Math.toRadians(b))*square(a); } public static double lozenge(double a,int b){ return Math.sin(Math.toRadians(b))*square(a); } public static double lozenge(int a,int b){ return Math.sin(Math.toRadians(b))*square(a); } //平方メートルを坪に変換 public static double M2toTSUBO(double a){ return a*TSUBO; } //三つの数値の中から最大のものを返す。 public static int max(int a,int b,int c){ int x=a; if(xb){x=b;} if(x>c){x=c;} return x; } public static double min(double a,double b,double c){ double x=a; if(x>b){x=b;} if(x>c){x=c;} return x; } public static long min(long a,long b,long c){ long x=a; if(x>b){x=b;} if(x>c){x=c;} return x; } //メートルをフィートに変換。 public static double MtoFEET(double a){ return a*FEET; } //メートルをヤードに変換。 public static double MtoYARD(double a){ return a*YARD; } //ルーローの三角形の面積を求める。aはルーローの三角形に内接する正三角形の一辺の長さ。 public static double RouleauTriangle(double a){ return a*a*Math.PI/2-a*a*Math.cos(Math.toRadians(30)); } //三角形の面積を返す。 public static int triangle(int a,int b){ return a*b/2; } public static double triangle(double a,double b){ return a*b/2; } public static long triangle(long a,long b){ return a*b/2; } //坪を平方メートルに変換 public static double TSUBOtoM2(double a){ return a/TSUBO; } //ランダムでtrueかfalseを返す。 public static boolean random(){ Random r=new Random(); int a=r.nextInt(2); boolean b=true; if(a==1){b=false;} return b; } //四捨五入 public static double round(double a){//普通に四捨五入 return Math.round(a); } public static double round(double a,double b){//aの数値のbの位を四捨五入 return Math.round(a/b)*b; } public static double round(double a,int b){//aの数値のbの位を四捨五入 return Math.round(a/b)*b; } //二乗の数値を返す。 public static int square(int a){ return a*a; } public static double square(double a){ return a*a; } public static long square(long a){ return a*a; } //ヤードをメートルに変換。 public static double YARDtoM(double a){ return a/YARD; } }