public seg segIntersect(seg segptr1,seg segptr2){
		seg newsegptr = null;
		  double begin, end;

		  seg firstseg, secondseg, tempseg;

		  if (segptr1 == null || segptr2 == null) {
		    System.out.println("stop! you did something wrong. null seg in seg intersect\n");
		  }

		  if (segptr1.begin < segptr2.begin) {
		    firstseg = segptr1;
		    secondseg = segptr2;
		  }
		  else {
		    firstseg = segptr2;
		    secondseg = segptr1;
		  }

		  while (firstseg != null && secondseg != null) {
		    /* which is first, first or 2nd? */
		    if (firstseg.begin > secondseg.begin) {
		      tempseg = firstseg;
		      firstseg = secondseg;
		      secondseg = tempseg;
		    }
				

		    /* if they overlap: */
		    if (firstseg.end > secondseg.begin) {
		      begin = secondseg.begin;
					
		      /* if second is wholly contained in first */
		      if (firstseg.end > secondseg.end) {
		    	  end = secondseg.end;
		    	  secondseg = secondseg.next;
		      }
					
		      else {
		    	  end = firstseg.end;
		    	  firstseg = firstseg.next;
		      }
					
		      newsegptr = segAdd(newsegptr, begin, end);
		    }
		    else {
		      firstseg = firstseg.next;
		    }
		  }

		  return newsegptr;
	}