-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmPointF.java
More file actions
executable file
·75 lines (69 loc) · 1.73 KB
/
mPointF.java
File metadata and controls
executable file
·75 lines (69 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* mPointF.java
* A customized floating point 2D point class.
*
* Created on March 17, 2006, 12:19 PM
*/
/**
* @author Chen-Fu Liao
* Sr. Systems Engineer
* ITS Institute, ITS Laboratory
* Center For Transportation Studies
* University of Minnesota
* 200 Transportation and Safety Building
* 511 Washington Ave. SE
* Minneapolis, MN 55455
*/
public class mPointF {
public float X ;
public float Y ;
/** Creates a new instance of mPoint */
public mPointF() {
}
public mPointF(float _x, float _y) {
X =_x;
Y =_y;
}
public mPointF(int _x, int _y) {
X =_x;
Y =_y;
}
// public methods here
public float getX() {
return X ;
}
public float getY() {
return Y ;
}
// compute unit vector
public mPointF unitVector() {
double len = Math.sqrt(X*X+Y*Y) ;
return new mPointF(new Double(X/len).floatValue(),
new Double(Y/len).floatValue()) ;
}
//get vector length
public float getLength() {
double L1 = Math.sqrt(X*X+Y*Y) ;
return new Double(L1).floatValue() ;
}
// vector dot product
public float dot (mPointF _vec) {
float L1 = getLength() ;
float L2 = _vec.getLength() ;
// return cosine value
return (X*_vec.X+Y*_vec.Y)/L1/L2 ;
}
public float dotVal (mPointF _vec) {
// return cosine value
return (X*_vec.X+Y*_vec.Y) ;
}
public String toStr() {
return "("+CStr(CInt(X*100f)/100f)+","+CStr(CInt(Y*100f)/100f)+")" ;
}
private int CInt(float val){
return new Float(val).intValue();
}
private String CStr(float val){
return new Float(val).toString();
}
}