Here you can find the source of normal0(double[] p1, double[] p2, double[] p3)
public static double[] normal0(double[] p1, double[] p2, double[] p3)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . j a v a 2 s . com computes the unit normal vector on the plane p1p2p3 as normalize(p2p1 x p2p3) */ public static double[] normal0(double[] p1, double[] p2, double[] p3) { double[] v21 = subtract(p1, p2); double[] v23 = subtract(p3, p2); return (normalize(crossprod(v21, v23))); } /** subtracts two vectors v1-v2 */ public static double[] subtract(double[] v1, double[] v2) { double[] v = new double[3]; v[0] = v1[0] - v2[0]; v[1] = v1[1] - v2[1]; v[2] = v1[2] - v2[2]; return (v); } /** returns vector v normalized */ public static double[] normalize(double[] v) { double[] v0 = new double[3]; double n = norm(v); v0[0] = v[0] / n; v0[1] = v[1] / n; v0[2] = v[2] / n; return (v0); } /** general cross product function for vectors in three dimensions */ public static double[] crossprod(double[] v1, double[] v2) { double[] v = new double[3]; v[0] = v1[1] * v2[2] - v1[2] * v2[1]; v[1] = v1[2] * v2[0] - v1[0] * v2[2]; v[2] = v1[0] * v2[1] - v1[1] * v2[0]; return (v); } /** returns the norm of the vector*/ public static double norm(double[] v) { return (Math.sqrt(dotprod(v, v))); } /** computes the dot product v1*v2.*/ public static double dotprod(double[] v1, double[] v2) { return (v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]); } }