View Javadoc
1 package edu.psu.geovista.app.intersection; 2 import java.util.Vector; 3 /*** 4 * Title: 5 * Description: 6 * Copyright: Copyright (c) 2002 7 * Company: 8 * @author 9 * @version 1.0 10 */ 11 12 public class intersection { 13 14 public intersection() { 15 } 16 /* 17 get the intersection point of each line of line1 with each line in line2. 18 check if the intersection point lies in both line segments. 19 if yes add the point to the vector intersectionLines and return the vector. 20 equation for line 21 (x-x1)/(x2-x1) = (y-y1)/(y2-y1) 22 23 format of intersectionLines(x1- xcordinate, y1-ycordinate, numberline1- position of intersecting line in line1, 24 numberline2- position of intersecting line in line2) 25 */ 26 public Vector getIntersection(Vector line1, Vector line2){ 27 Vector intersectionLines= new Vector(); 28 29 Vector tmp; 30 Vector intersect; 31 Vector tline1; 32 Vector tline2; 33 double xvalue1; 34 double yvalue1; 35 double cons1; 36 double xvalue2; 37 double yvalue2; 38 double cons2; 39 40 double x1one; 41 double x2one; 42 double y1one; 43 double y2one; 44 double x1two; 45 double x2two; 46 double y1two; 47 double y2two; 48 double xintersect; 49 double yintersect; 50 for (int line1count=0;line1count < line1.size();line1count++) 51 { 52 // getting values of xcordinate, ycordinate and constant from line1 53 tline1 = (Vector)line1.elementAt(line1count); 54 x1one = ((Double)tline1.elementAt(1)).doubleValue(); 55 x2one = ((Double)tline1.elementAt(2)).doubleValue(); 56 y1one = ((Double)tline1.elementAt(3)).doubleValue(); 57 y2one = ((Double)tline1.elementAt(4)).doubleValue(); 58 xvalue1 = y2one - y1one; 59 yvalue1 = x2one - x1one; 60 cons1 = ((y2one - y1one)*x1one)-((x2one - x1one)*y1one); 61 for (int line2count=0;line2count < line2.size();line2count++) 62 { 63 //compare each line1 with all line2 64 // getting values of xcordinate, ycordinate and constant from line2 65 tline2 = (Vector)line2.elementAt(line2count); 66 x1two = ((Double)tline2.elementAt(1)).doubleValue(); 67 x2two = ((Double)tline2.elementAt(2)).doubleValue(); 68 y1two = ((Double)tline2.elementAt(3)).doubleValue(); 69 y2two = ((Double)tline2.elementAt(4)).doubleValue(); 70 xvalue2 = y2two - y1two; 71 yvalue2 = x2two - x1two; 72 cons2 = ((y2two - y1two)*x1two)-((x2two - x1two)*y1two); 73 //find the intersecting point 74 xintersect=((yvalue2 * cons1)-(yvalue1 * cons2))/((yvalue2 * xvalue1)-(yvalue1 * xvalue2)); 75 yintersect=((xvalue2 * cons1)-(xvalue1 * cons2))/((xvalue2 * yvalue1)-(xvalue1 * yvalue2)); 76 intersect = new Vector(); 77 // add the intersecting point 78 intersect.add(new Double(xintersect)); 79 intersect.add(new Double(yintersect)); 80 if(CheckIntersectionTrue(tline1, tline2, intersect)) 81 { 82 tmp = new Vector(); 83 //add to the intersectionLines List 84 tmp.add(((Vector)intersect).elementAt(0)); 85 tmp.add(((Vector)intersect).elementAt(1)); 86 tmp.add( new Integer(line1count)); 87 tmp.add(new Integer(line2count)); 88 intersectionLines.add(tmp); 89 } 90 } 91 } 92 return intersectionLines; 93 } 94 /* 95 Check if the intersecting point of the two lines lies between the two line segments. 96 returns true if the line segments have the point. 97 returns false if atleast one of the lines dont have the point. 98 */ 99 public boolean CheckIntersectionTrue(Vector line1, Vector line2,Vector intersectingPoint){ 100 boolean temp = true; 101 double x1one = ((Double)line1.elementAt(1)).doubleValue(); 102 double x2one = ((Double)line1.elementAt(2)).doubleValue(); 103 double y1one = ((Double)line1.elementAt(3)).doubleValue(); 104 double y2one = ((Double)line1.elementAt(4)).doubleValue(); 105 double x1two = ((Double)line2.elementAt(1)).doubleValue(); 106 double x2two = ((Double)line2.elementAt(2)).doubleValue(); 107 double y1two = ((Double)line2.elementAt(3)).doubleValue(); 108 double y2two = ((Double)line2.elementAt(4)).doubleValue(); 109 double xintersect= ((Double)intersectingPoint.elementAt(1)).doubleValue(); 110 double yintersect= ((Double)intersectingPoint.elementAt(2)).doubleValue(); 111 112 if (checkxy(x1one,x2one,xintersect)) 113 { 114 if (checkxy(y1one,y2one,yintersect)) 115 { 116 if (checkxy(x1two,x2two,yintersect)) 117 { 118 if (checkxy(y1two,y2two,yintersect)) 119 { 120 temp = true; 121 } 122 else 123 temp =false; 124 } 125 else 126 temp = false; 127 } 128 else 129 temp =false; 130 } 131 else 132 temp = false; 133 return temp; 134 } 135 public boolean checkxy(double xy1, double xy2, double xy) 136 { 137 if (xy1 > xy2) 138 { 139 if (xy<= xy1 & xy >=xy2) 140 { 141 return true; 142 } 143 else 144 return false; 145 } 146 else 147 { 148 if (xy>= xy1 & xy<=xy2) 149 { 150 return true; 151 } 152 else 153 return false; 154 } 155 } 156 }

This page was automatically generated by Maven