1 /*
2 * The contents of this file are subject to the BT "ZEUS" Open Source
3 * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file
4 * except in compliance with the Licence. You may obtain a copy of the Licence
5 * from $ZEUS_INSTALL/licence.html or alternatively from
6 * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7 *
8 * Except as stated in Clause 7 of the Licence, software distributed under the
9 * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or
10 * implied. See the Licence for the specific language governing rights and
11 * limitations under the Licence.
12 *
13 * The Original Code is within the package zeus.*.
14 * The Initial Developer of the Original Code is British Telecommunications
15 * public limited company, whose registered office is at 81 Newgate Street,
16 * London, EC1A 7AJ, England. Portions created by British Telecommunications
17 * public limited company are Copyright 1996-9. All Rights Reserved.
18 *
19 * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20 */
21
22
23
24 package zeus.util;
25
26 import java.util.*;
27 import java.awt.*;
28
29 public class ArrowData {
30
31 public static final double ARROW_ANGLE = Math.PI/12.0;
32 public static final double ARROW_RATIO = 0.1;
33 public static final double ARROW_LMIN = 7;
34 public static final double ARROW_LMAX = 14;
35 public static final double ARROW_LENGTH = 10;
36 public static final double MTOL = 1.0E-12;
37
38 public static Point[] getPoints( double x1, double y1, double x2, double y2 ) {
39
40 double L, A, B;
41 Point[] xpoints = new Point[4];
42 for( int i = 0; i < 4; i++ )
43 xpoints[i] = new Point(0,0);
44
45 // L = Math.sqrt( Math.pow(y2-y1,2.0)+Math.pow(x2-x1,2.0) );
46 // L *= ARROW_RATIO;
47
48 // if ( L < ARROW_LMAX || L > ARROW_LMIN ) L = ARROW_LENGTH;
49 L = ARROW_LENGTH;
50
51 B = GetAngle(x1,y1,x2,y2);
52 A = B-ARROW_ANGLE;
53
54 xpoints[0].x = (int) (x2-L*Math.cos(A));
55 xpoints[0].y = (int) (y2-L*Math.sin(A));
56
57 xpoints[1].x = (int) x2;
58 xpoints[1].y = (int) y2;
59
60 A = B+ARROW_ANGLE;
61
62 xpoints[2].x = (int) (x2-L*Math.cos(A));
63 xpoints[2].y = (int) (y2-L*Math.sin(A));
64
65 xpoints[3].x = xpoints[0].x;
66 xpoints[3].y = xpoints[0].y;
67
68 return xpoints;
69 }
70
71 public static double GetAngle( double x1, double y1, double x2, double y2 ) {
72 double B, x, y;
73
74 x = x2 - x1;
75 y = y2 - y1;
76
77 if ( Math.abs(x) < MTOL && Math.abs(y) < MTOL ) return( 0.0 );
78
79 B = Math.atan(y/x);
80
81 if ( x >= 0.0 && y >= 0.0 ) B += 0.0;
82 else if ( x < 0.0 && y >= 0.0 ) B += Math.PI;
83 else if ( x < 0.0 && y < 0.0 ) B += Math.PI;
84 else if ( x >= 0.0 && y < 0.0 ) B += 2.0*Math.PI;
85
86 return( B );
87 }
88
89 }
90