Worldwind public release 0.2.1
[worldwind-tracker.git] / gov / nasa / worldwind / geom / Triangle.java
blobbb287d8fd30b89700d4095027b554390fd77b28b
1 /*
2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
5 All Rights Reserved.
6 */
7 package gov.nasa.worldwind.geom;
9 import gov.nasa.worldwind.*;
11 /**
12 * @author Eric Dalgliesh 30/11/2006
13 * @version $Id: Triangle.java 1991 2007-06-09 23:27:42Z dcollins $
15 public class Triangle
17 private static final double EPSILON = 0.0000001; // used in intersects method
19 private final Vec4 a;
20 private final Vec4 b;
21 private final Vec4 c;
23 public Triangle(Vec4 a, Vec4 b, Vec4 c)
25 if (a == null || b == null || c == null)
27 String msg = WorldWind.retrieveErrMsg("nullValue.PointIsNull");
28 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
29 throw new IllegalArgumentException(msg);
32 this.a = a;
33 this.b = b;
34 this.c = c;
37 // private Plane getPlane()
38 // {
39 // Vector ab, ac;
40 // ab = new Vector(this.b.subtract(this.a)).normalize();
41 // ac = new Vector(this.c.subtract(this.a)).normalize();
43 // Vector n = new Vector(new Point(ab.x(), ab.y(), ab.z(), ab.w()).cross(new Point(ac.x(), ac.y(), ac.z(), ac.w())));
45 // return new gov.nasa.worldwind.geom.Plane(n);
46 // }
48 // private Point temporaryIntersectPlaneAndLine(Line line, Plane plane)
49 // {
50 // Vector n = line.getDirection();
51 // Point v0 = Point.fromOriginAndDirection(plane.getDistance(), plane.getNormal(), Point.ZERO);
52 // Point p0 = line.getPointAt(0);
53 // Point p1 = line.getPointAt(1);
55 // double r1 = n.dot(v0.subtract(p0))/n.dot(p1.subtract(p0));
56 // if(r1 >= 0)
57 // return line.getPointAt(r1);
58 // return null;
59 // }
61 // private Triangle divide(double d)
62 // {
63 // d = 1/d;
64 // return new Triangle(this.a.multiply(d), this.b.multiply(d), this.c.multiply(d));
65 // }
67 // public Point intersect(Line line)
68 // {
69 // // taken from Moller and Trumbore
70 // // http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/
71 // // Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf
73 // Point origin = line.getOrigin();
74 // Point dir = new Point(line.getDirection());
76 // double u, v;
78 // // find vectors for two edges sharing Point a
79 // Point edge1 = this.c.subtract(this.a);
80 // Point edge2 = this.b.subtract(this.a);
82 // // start calculating determinant
83 // Point pvec = dir.cross(edge2);
85 // // get determinant.
86 // double det = edge1.dot(pvec);
88 // if (det > -EPSILON && det < EPSILON)
89 // {// If det is near zero, then ray lies on plane of triangle
90 // return null;
91 // }
93 // double detInv = 1d / det;
95 // // distance from vert0 to ray origin
96 // Point tvec = origin.subtract(this.a);
98 // // calculate u parameter and test bounds
99 // u = tvec.dot(pvec) * detInv;
100 // if (u < 0 || u > 1)
101 // {
102 // return null;
103 // }
105 // // prepare to test v parameter
106 // Point qvec = tvec.cross(edge1);
108 // //calculate v parameter and test bounds
109 // v = dir.dot(qvec) * detInv;
110 // if (v < 0 || u + v > 1)
111 // {
112 // return null;
113 // }
115 // double t = edge2.dot(qvec) * detInv;
116 // return Point.fromOriginAndDirection(t, line.getDirection(), line.getOrigin());
118 //// return new Point(t, u, v);
119 //// return line.getPointAt(t);
120 // }