[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Line.java, 1.20, 1.21
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2006-08-29 09:31:04
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv4318/src/net/sourceforge/bprocessor/model Modified Files: Line.java Log Message: Added method for intersection with an other line Index: Line.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Line.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Line.java 11 Aug 2006 12:44:21 -0000 1.20 --- Line.java 29 Aug 2006 09:30:57 -0000 1.21 *************** *** 13,23 **** import java.util.Set; /** * The line constructor type */ public class Line extends Constructor { /** The direction vector */ private Vertex dir; ! /** * Empty constructor for persistence only --- 13,33 ---- import java.util.Set; + import org.apache.log4j.Logger; + /** * The line constructor type */ public class Line extends Constructor { + /** + * + */ + private static final long serialVersionUID = 1L; + + /** The logger */ + private static Logger log = Logger.getLogger(Line.class); + /** The direction vector */ private Vertex dir; ! /** * Empty constructor for persistence only *************** *** 26,30 **** super(); } ! /** * Constuctor of Line with only the origin and a standard direction of (1,0,0) --- 36,40 ---- super(); } ! /** * Constuctor of Line with only the origin and a standard direction of (1,0,0) *************** *** 34,38 **** this(origin, new Vertex(1, 0, 0), false); } ! /** * Constructor of the Line with orgin and three angles --- 44,48 ---- this(origin, new Vertex(1, 0, 0), false); } ! /** * Constructor of the Line with orgin and three angles *************** *** 43,47 **** this(origin, dir, false); } ! /** * Constructor of the Line with orgin and three angles --- 53,57 ---- this(origin, dir, false); } ! /** * Constructor of the Line with orgin and three angles *************** *** 56,60 **** this.dir = dir; } ! /** * Constructor of the Line with orgin and three angles --- 66,70 ---- this.dir = dir; } ! /** * Constructor of the Line with orgin and three angles *************** *** 69,73 **** this.dir = dir; } ! /** * Get a direction vector for the line --- 79,83 ---- this.dir = dir; } ! /** * Get a direction vector for the line *************** *** 77,81 **** return dir; } ! /** * Collects the set of vertices in this geometric --- 87,91 ---- return dir; } ! /** * Collects the set of vertices in this geometric *************** *** 111,115 **** dir.normalize(); } ! /** * @see net.sourceforge.bprocessor.model.Parametric#setAttributes() --- 121,125 ---- dir.normalize(); } ! /** * @see net.sourceforge.bprocessor.model.Parametric#setAttributes() *************** *** 117,121 **** public void setAttributes(List attributes) { Vertex orig = new Vertex(0, 0, 0); ! orig.setX(((Double)(((Attribute)attributes.get(1)).getValue())).doubleValue()); orig.setY(((Double)(((Attribute)attributes.get(2)).getValue())).doubleValue()); --- 127,131 ---- public void setAttributes(List attributes) { Vertex orig = new Vertex(0, 0, 0); ! orig.setX(((Double)(((Attribute)attributes.get(1)).getValue())).doubleValue()); orig.setY(((Double)(((Attribute)attributes.get(2)).getValue())).doubleValue()); *************** *** 133,137 **** setEditable(((Boolean)(((Attribute)attributes.get(11)).getValue())).booleanValue()); } ! /** * @see net.sourceforge.bprocessor.model.Parametric#getAttributes() --- 143,147 ---- setEditable(((Boolean)(((Attribute)attributes.get(11)).getValue())).booleanValue()); } ! /** * @see net.sourceforge.bprocessor.model.Parametric#getAttributes() *************** *** 168,172 **** return "Line"; } ! /** * Print a line --- 178,182 ---- return "Line"; } ! /** * Print a line *************** *** 183,187 **** return Geometry.degreesAboutY(dir); } ! /** * @see @see net.sourceforge.bprocessor.model.Geometry#degreesAboutZ(Vertex) --- 193,197 ---- return Geometry.degreesAboutY(dir); } ! /** * @see @see net.sourceforge.bprocessor.model.Geometry#degreesAboutZ(Vertex) *************** *** 190,194 **** return Geometry.degreesAboutZ(dir); } ! /** * Tip --- 200,204 ---- return Geometry.degreesAboutZ(dir); } ! /** * Tip *************** *** 198,202 **** return tip(1.0); } ! /** * Tip --- 208,212 ---- return tip(1.0); } ! /** * Tip *************** *** 210,214 **** return new Tip(x, y, z); } ! /** * @param distance distance --- 220,224 ---- return new Tip(x, y, z); } ! /** * @param distance distance *************** *** 220,224 **** return list; } ! /** * Return an edge for this line --- 230,234 ---- return list; } ! /** * Return an edge for this line *************** *** 236,239 **** --- 246,315 ---- return constructor; } + + /** + * Return the intersection point between this and an other line + * @param l a line + * @return intersection point, null if no point exists + */ + public Vertex intersection(Line l) { + //algorithm inspired by geometryalgorithms.com + Vertex o = this.getOrigin(); + Vertex d = this.getDirection().copy(); + Vertex p = l.getOrigin(); + Vertex c = l.getDirection().copy(); + double u1; + double u2; + double v1; + double v2; + double w1; + double w2; + if (d.getX() != 0 || c.getX() != 0) { + u1 = d.getX(); + v1 = c.getX(); + w1 = p.getX() - o.getX(); + if (d.getY() != 0 || c.getY() != 0) { + u2 = d.getY(); + v2 = c.getY(); + w2 = p.getY() - o.getY(); + } else if (d.getZ() != 0 || c.getZ() != 0) { + u2 = d.getZ(); + v2 = c.getZ(); + w2 = p.getZ() - o.getZ(); + } else { + return null; + } + } else if (d.getY() != 0 || c.getY() != 0) { + u1 = d.getY(); + v1 = c.getY(); + w1 = p.getY() - o.getY(); + if (d.getZ() != 0 || c.getZ() != 0) { + u2 = d.getZ(); + v2 = c.getZ(); + w2 = p.getZ() - o.getZ(); + } else { + return null; + } + } else { + return null; + } + double denom = v1 * u2 - v2 * u1; + if (denom == 0) { + //lines are parrallel + return null; + } + double s = ((v2 * w1 - v1 * w2) / denom); + double t = ((u1 * w2 - u2 * w1) / -denom); + + d.scale(-s); + c.scale(-t); + Vertex inter1 = d.add(o); + Vertex inter2 = c.add(p); + if (inter1.equalEps(inter2)) { + //lines are not in the same plane + return inter1; + } else { + return null; + } + } /** *************** *** 258,262 **** setDirection(minus(getOrigin())); } ! /** * Return the line --- 334,338 ---- setDirection(minus(getOrigin())); } ! /** * Return the line *************** *** 266,270 **** return Line.this; } ! /** * @return string --- 342,346 ---- return Line.this; } ! /** * @return string *************** *** 274,278 **** } } ! /** * Guide --- 350,354 ---- } } ! /** * Guide *************** *** 280,283 **** --- 356,364 ---- private class Guide extends Edge { /** + * + */ + private static final long serialVersionUID = 1L; + + /** * Constructor * @param from Vertex *************** *** 287,291 **** super(from, to); } ! /** * Parent --- 368,372 ---- super(from, to); } ! /** * Parent *************** *** 296,300 **** } } ! /** @see net.sourceforge.bprocessor.model.Geometric#getName() */ public String getName() { --- 377,381 ---- } } ! /** @see net.sourceforge.bprocessor.model.Geometric#getName() */ public String getName() { |