Ejemplo n.º 1
0
 /**
  * 法線を求める
  *
  * @param V 頂点配列
  * @param A 頂点の位置
  * @param B 頂点の位置
  * @param C 頂点の位置
  * @return 法線ベクトル
  */
 protected KGLPoint calcNormal(KGLPoint[] V, int A, int B, int C) {
   KGLPoint ret = null;
   KGLPoint BA = null;
   KGLPoint BC = null;
   // ベクトルB->A
   BA = KGLPoint.vector(V[B], V[A]);
   // ベクトルB->C
   BC = KGLPoint.vector(V[B], V[C]);
   // 法線の計算
   ret =
       KGLPoint.createXYZ(
           BA.Y() * BC.Z() - BA.Z() * BC.Y(),
           BA.Z() * BC.X() - BA.X() * BC.Z(),
           BA.X() * BC.Y() - BA.Y() * BC.X());
   ret.normalize(); // 正規化
   return ret;
 }