[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Plane.java,1.2,1.3
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2005-08-30 13:12:18
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6819/src/net/sourceforge/bprocessor/model Modified Files: Plane.java Log Message: Clicking at the XY plane works Index: Plane.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Plane.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Plane.java 26 Aug 2005 14:49:23 -0000 1.2 --- Plane.java 30 Aug 2005 13:11:32 -0000 1.3 *************** *** 51,55 **** * @return the intersection with the (x y t) ray or NaN */ ! double intersection(double x, double y) { if (c != 0) { return -(a * x + b * y + d) / c; --- 51,55 ---- * @return the intersection with the (x y t) ray or NaN */ ! public double intersection(double x, double y) { if (c != 0) { return -(a * x + b * y + d) / c; *************** *** 58,61 **** --- 58,89 ---- } } + + /** + * Find the intersection with the ray originating at origin + * with the specified direction + * @param origin The origin of the ray + * @param direction The direction of the ray + * @return The intersection point + */ + public Vertex intersection(Vertex origin, Vertex direction) { + double x0 = origin.getX(); + double y0 = origin.getY(); + double z0 = origin.getZ(); + double xd = direction.getX(); + double yd = direction.getY(); + double zd = direction.getZ(); + double vd = a * xd + b * yd + c * zd; + if (vd != 0) { + double v0 = -(a * x0 + b * y0 + c * z0 + d); + double t = v0 / vd; + Vertex i = new Vertex("intersection"); + i.setX(x0 + t * xd); + i.setY(y0 + t * yd); + i.setZ(z0 + t * zd); + return i; + } else { + return null; + } + } } |