1 package com.generalrobotix.ui.util;
3 import javax.vecmath.Matrix3d;
4 import javax.vecmath.Vector3d;
8 public static Vector3d
calcScale(Matrix3d I,
double m){
9 Matrix3d R =
new Matrix3d();
10 Matrix3d II =
new Matrix3d();
12 double sum = II.m00+II.m11+II.m22;
13 Vector3d sv =
new Vector3d(
14 m*Math.sqrt(sum/II.m00),
15 m*Math.sqrt(sum/II.m11),
16 m*Math.sqrt(sum/II.m22));
19 System.out.println(
"diagonalization failed");
21 return new Vector3d(0,0,0);
31 private static boolean diagonalize(Matrix3d a, Matrix3d U, Matrix3d W){
32 int i=0,
j=0,l,m,p,q,count;
34 Matrix3d oldU =
new Matrix3d();
35 Matrix3d newW =
new Matrix3d();
42 U.setElement(p, q, 1.0);
44 U.setElement(p, q, 0.0);
49 for(count=0;count<=10000;count++) {
54 oldU.setElement(p, q, U.getElement(p, q));
61 if(max<Math.abs(W.getElement(p, q)) && p!=q) {
62 max=Math.abs(W.getElement(p, q));
74 if(W.getElement(i,i)==W.getElement(
j,
j)){
77 theta=Math.atan(-2*W.getElement(i,
j)/(W.getElement(i,i)-W.getElement(
j,
j)))/2.0;
81 double sth = Math.sin(theta);
82 double cth = Math.cos(theta);
86 U.setElement(p,i,oldU.getElement(p,i)*cth-oldU.getElement(p,
j)*sth);
87 U.setElement(p,
j,oldU.getElement(p,i)*sth+oldU.getElement(p,
j)*cth);
91 newW.setElement(i,i,W.getElement(i,i)*cth*cth
92 +W.getElement(
j,
j)*sth*sth-2.0*W.getElement(i,
j)*sth*cth);
93 newW.setElement(
j,
j, W.getElement(i,i)*sth*sth
94 +W.getElement(
j,
j)*cth*cth+2.0*W.getElement(i,
j)*sth*cth);
95 newW.setElement(i,
j,0.0);
96 newW.setElement(
j,i,0.0);
99 newW.setElement(i,l,W.getElement(i,l)*cth-W.getElement(
j,l)*sth);
100 newW.setElement(l,i,newW.getElement(i,l));
101 newW.setElement(
j,l,W.getElement(i,l)*sth+W.getElement(
j,l)*cth);
102 newW.setElement(l,
j,newW.getElement(
j,l));
107 if(l!=i && l!=
j && m!=i && m!=
j) newW.setElement(l, m, W.getElement(l,m));
116 System.out.println(
"対角化するためにはまだ作業を繰り返す必要があります");
static boolean diagonalize(Matrix3d a, Matrix3d U, Matrix3d W)
diagonalize symmetric matrix
static Vector3d calcScale(Matrix3d I, double m)
def j(str, encoding="cp932")
static int max(int a, int b)