// Path: kendzi-math-geometry/src/main/java/kendzi/math/geometry/point/Vector3dUtil.java
// public class Vector3dUtil {
//     public static Vector3d fromTo(Tuple3d from, Tuple3d to) {
//         Vector3d v = new Vector3d(to);
//         v.sub(from);
//         return v;
//     }
// 
// }


import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import kendzi.math.geometry.point.Vector3dUtil;

package kendzi.math.geometry.intersection;



/**
 * Intersection util.
 * 
 * @author Tomasz Kedziora (Kendzi)
 *
 */
public class IntersectionUtil {

    /**
     * Check whatever ray intersect triangle.
     *
     * @see <a
     *      href="http://www.lighthouse3d.com/tutorials/maths/ray-triangle-intersection/">lighthouse3d
     *      example</a>
     * @param p
     *            ray start point
     * @param d
     *            ray direction vector
     * @param v0
     *            triangle first point
     * @param v1
     *            triangle second point
     * @param v2
     *            triangle third point
     * @return if ray intersect triangle.
     */
    public static boolean rayIntersectsTriangle(Point3d p, Vector3d d, Point3d v0, Point3d v1, Point3d v2) {

        double a, f, u, v;


// Path: kendzi-math-geometry/src/main/java/kendzi/math/geometry/point/Vector3dUtil.java
// public class Vector3dUtil {
//     public static Vector3d fromTo(Tuple3d from, Tuple3d to) {
//         Vector3d v = new Vector3d(to);
//         v.sub(from);
//         return v;
//     }
// 
// }


// Path: kendzi-math-geometry/src/main/java/kendzi/math/geometry/intersection/IntersectionUtil.java
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import kendzi.math.geometry.point.Vector3dUtil;

package kendzi.math.geometry.intersection;



/**
 * Intersection util.
 * 
 * @author Tomasz Kedziora (Kendzi)
 *
 */
public class IntersectionUtil {

    /**
     * Check whatever ray intersect triangle.
     *
     * @see <a
     *      href="http://www.lighthouse3d.com/tutorials/maths/ray-triangle-intersection/">lighthouse3d
     *      example</a>
     * @param p
     *            ray start point
     * @param d
     *            ray direction vector
     * @param v0
     *            triangle first point
     * @param v1
     *            triangle second point
     * @param v2
     *            triangle third point
     * @return if ray intersect triangle.
     */
    public static boolean rayIntersectsTriangle(Point3d p, Vector3d d, Point3d v0, Point3d v1, Point3d v2) {

        double a, f, u, v;


        Vector3d e1 = Vector3dUtil.fromTo(v0, v1);
