Revision 8338 trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/graph/core/TurnUtil.java

View differences:

TurnUtil.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.2  2006-10-23 18:51:42  azabala
48
* Revision 1.3  2006-10-25 15:51:20  fjp
49
* por terminar lo de los giros
50
*
51
* Revision 1.2  2006/10/23 18:51:42  azabala
49 52
* *** empty log message ***
50 53
*
51 54
* Revision 1.1  2006/10/20 19:54:01  azabala
......
92 95
	    
93 96
		 double dx = p1.x - p0.x;
94 97
	     double dy = p1.y - p0.y;
95
	     double angle1 = Math.atan2(dy, dx);
98
//	     double angle1 = Math.toDegrees(Math.atan2(dy, dx));
99
	     double angle1 = returnAngle(p0, p1);
96 100
	
97 101
	     dx = p2.x - p1.x;
98 102
	     dy = p2.y - p1.y;
99
	     double angle2 = Math.atan2(dy, dx);
103
	     double angle2 = returnAngle(p1, p2); // Math.toDegrees(Math.atan2(dy, dx));
100 104
	  
101
	     double turnAngle = angle1 - angle2;
102
	     double deegreeAngle = Math.toDegrees(turnAngle);
103
	    
105
	     double deegreeAngle = angle1 - angle2;
106
	         
104 107
	     if (Math.abs(deegreeAngle) > 180){
105 108
	    	 if(deegreeAngle < 0){
106 109
	    		 deegreeAngle = 360 - Math.abs(deegreeAngle);
......
117 120
	    	 return TURN_RIGHT;
118 121
	}	
119 122
	
123
	public static double returnAngle(Coordinate c1, Coordinate c2) {
124
		  double dx, dy;
125
		  dx = c1.x - c2.x;
126
		  dy = c1.y - c2.y;
127
		  double resul = 0;
128
		  if ((dx == 0) && (dy == 0)) 
129
		  	return resul;
130
		  if (dx == 0) 
131
		    return 90.0;
132
		  
133
		  // resul = Atn(Abs(dy) / Abs(dx)) * 57.2957795131 'Compute angle in degrees
134
		  resul = Math.atan(Math.abs(dy) / Math.abs(dx));
135
		  resul = Math.toDegrees(resul);
136
		  if (dx < 0)
137
			  return 180 - resul;
138
		  if (dy < 0)
139
			  return (360 - resul);
140
		  return resul;
141
	}
120 142
	
121 143
	/**
122 144
	 * 

Also available in: Unified diff