Skip to content

Commit a61b28f

Browse files
committed
Javadoc math package
1 parent 80fdaaf commit a61b28f

File tree

6 files changed

+177
-10
lines changed

6 files changed

+177
-10
lines changed

core/src/com/group/golf/math/BicubicInterpolator.java

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
/**
44
* A class to use bicubic polynomials for interpolation
5+
* @author Kaspar Kallast
6+
* @author Julian Marrades
57
*/
68
public class BicubicInterpolator implements Computable {
79

@@ -105,6 +107,12 @@ private void fitter(float[][] dx, float[][] dy, float[][] dxy) {
105107
this.coefficients = MathLib.multiply(res1, B);
106108
}
107109

110+
/**
111+
* Make use of the coefficients to compute f(x, y)
112+
* @param x the x-component of the coordinate
113+
* @param y the y-component of the coordinate
114+
* @return z = f(x, y)
115+
*/
108116
@Override
109117
public float getZ(float x, float y) {
110118
float result = 0;

core/src/com/group/golf/math/Computable.java

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/**
44
* An interface for holding Computable objects, those that yield a Z out of an X and Y
5+
* @author Julian Marrades
56
*/
67
public interface Computable {
78

core/src/com/group/golf/math/Interpolator.java

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
/**
44
* A class to hold static methods for interpolation
5+
* @author Kaspar Kallast
6+
* @author Julian Marrades
57
*/
68
public class Interpolator {
79

core/src/com/group/golf/math/JVector2.java

+124-10
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,264 @@
11
package com.group.golf.math;
22

3+
/**
4+
* A class to represent a vector in R2 (2D space)
5+
* @author Julian Marrades
6+
*/
37
public class JVector2 {
48

59
private float x;
610
private float y;
711
private float magnitude;
812

13+
/**
14+
* Create a new instance of JVector2
15+
* @param x the x-component
16+
* @param y the y-component
17+
*/
918
public JVector2(float x, float y) {
1019
this.x = x;
1120
this.y = y;
1221
this.updateMagnitude();
1322
}
1423

24+
/**
25+
* Create a new instace of JVector2 from another instance
26+
* @param other the JVector2 template
27+
*/
1528
public JVector2(JVector2 other) {
1629
this.x = other.x;
1730
this.y = other.y;
1831
this.updateMagnitude();
1932
}
2033

34+
/**
35+
* Update the magnitude using the components
36+
*/
2137
private void updateMagnitude() {
2238
this.magnitude = (float)Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2));
2339
}
2440

41+
/**
42+
* Get access to the x-component
43+
* @return the x-component
44+
*/
2545
public float getX() {
2646
return x;
2747
}
2848

29-
public float floatX() {
30-
return (float) this.x;
31-
}
32-
49+
/**
50+
* Get access to the x-component truncated as an integer
51+
* @return the integer value of the x-component
52+
*/
3353
public int intX() {
3454
return (int) x;
3555
}
3656

57+
/**
58+
* Get access to the y-component
59+
* @return the y-component
60+
*/
3761
public float getY() {
3862
return y;
3963
}
4064

41-
public float floatY() {
42-
return (float) this.y;
43-
}
44-
65+
/**
66+
* Get access to the y-component truncated as an integer
67+
* @return the integer value of the y-component
68+
*/
4569
public int intY() {
4670
return (int) y;
4771
}
4872

73+
/**
74+
* Get the magnitute of the vector
75+
* @return the magnitude of the vector
76+
*/
4977
public float getMagnitude() {
5078
return this.magnitude;
5179
}
5280

81+
/**
82+
* Scale (mulitiply) the vector
83+
* @param scalar the scalar value to apply
84+
*/
5385
public void multiply(float scalar) {
5486
x = x * scalar;
5587
y = y * scalar;
5688
magnitude = magnitude * scalar;
5789
}
5890

91+
/**
92+
* Scale (divide) the vector
93+
* @param scalar the scalar value to apply
94+
*/
5995
public void divide(float scalar) {
6096
x = x / scalar;
6197
y = y / scalar;
6298
magnitude = magnitude / scalar;
6399
}
64100

101+
/**
102+
* Normalize the vector, set its magnitude to 1
103+
*/
65104
public void normalize() {
66105
x = x / magnitude;
67106
y = y / magnitude;
68107
magnitude = 1;
69108
}
70109

110+
/**
111+
* Set a new magnitude for the vector
112+
* @param number the new magnitude
113+
*/
71114
public void setMagnitude(float number) {
72115
this.normalize();
73116
this.multiply(number);
74117
}
75118

119+
/**
120+
* Limit the magnitude of the vector
121+
* @param value upper limit for the magnitude
122+
*/
76123
public void limit(float value) {
77124
if (this.getMagnitude() > value) {
78125
this.setMagnitude(value);
79126
}
80127
}
81128

129+
/**
130+
* Swap the components of the vector
131+
*/
82132
public void swap() {
83133
float tmp = this.x;
84134
this.x = this.y;
85135
this.y = tmp;
86136
}
87137

138+
/**
139+
* Set a new position for the vector
140+
* @param x the new x-coordinate
141+
* @param y the new y-coordinate
142+
*/
88143
public void setPosition(float x, float y) {
89144
this.x = x; this.y = y;
90145
}
91146

147+
/**
148+
* Invert a vector
149+
* @param vector the vector to invert
150+
* @return the a new instance with the swapped components of vector
151+
*/
92152
public static JVector2 opposite(JVector2 vector) {
93153
float invX = vector.y;
94154
float invY = vector.x;
95155
return new JVector2(invX, invY);
96156
}
97157

158+
/**
159+
* Perform vector sum
160+
* @param vector the vector to add to the current instance
161+
*/
98162
public void add(JVector2 vector) {
99163
x += vector.x;
100164
y += vector.y;
101-
magnitude = getMagnitude();
165+
this.updateMagnitude();
102166
}
103167

168+
/**
169+
* Perform vector subtraction
170+
* @param vector the vector to subtract to the current instance
171+
*/
104172
public void sub(JVector2 vector) {
105173
x -= vector.x;
106174
y -= vector.y;
107-
magnitude = getMagnitude();
175+
this.updateMagnitude();
108176
}
109177

178+
/**
179+
* Static vector sum
180+
* @param vector1 the first vector
181+
* @param vector2 the second vector
182+
* @return a vector which is the sum of vector1 and vector2
183+
*/
110184
public static JVector2 add2Vecs(JVector2 vector1, JVector2 vector2) {
111185
float sumX = vector1.getX() + vector2.getX();
112186
float sumY = vector1.getY() + vector2.getY();
113187
return new JVector2(sumX, sumY);
114188
}
115189

190+
/**
191+
* Static vector subtraction
192+
* @param vector1 the first vector
193+
* @param vector2 the second vector
194+
* @return a vector which is the subtraction of vector2 to vector1
195+
*/
116196
public static JVector2 sub2Vecs(JVector2 vector1, JVector2 vector2) {
117197
float subX = vector1.getX() - vector2.getX();
118198
float subY = vector1.getY() - vector2.getY();
119199
return new JVector2(subX, subY);
120200
}
121201

202+
/**
203+
* Euclidean distance between the tips of two vectors
204+
* @param vector1 the first vector
205+
* @param vector2 the second vector
206+
* @return euclidean distance between the tips of vector1 and vector2
207+
*/
122208
public static float dist2Vecs(JVector2 vector1, JVector2 vector2) {
123209
float intervalX = vector2.getX() - vector1.getX();
124210
float intervalY = vector2.getY() - vector1.getY();
125211
float distance = (float)Math.sqrt(Math.pow(intervalX, 2) + Math.pow(intervalY, 2));
126212
return distance;
127213
}
128214

215+
/**
216+
* Euclidean distance between two points in R2
217+
* @param x1 first x-coordinate
218+
* @param y1 first y-coordinate
219+
* @param x2 second x-coordinate
220+
* @param y2 second y-coordinate
221+
* @return euclidean distance between (x1, y1) and (x2, y2)
222+
*/
129223
public static float dist(float x1, float y1, float x2, float y2) {
130224
float intervalX = x2 - x1;
131225
float intervalY = y2 - y1;
132226
float distance = (float)Math.sqrt(Math.pow(intervalX, 2) + Math.pow(intervalY, 2));
133227
return distance;
134228
}
135229

230+
/**
231+
* Dot product of two vectors
232+
* @param vector1 the first vector
233+
* @param vector2 the second vector
234+
* @return the dot product of vector1 and vector 2
235+
*/
136236
public static float dotProduct(JVector2 vector1, JVector2 vector2) {
137237
float result = vector1.getX() * vector2.getX() + vector1.getY() * vector2.getY();
138238
return result;
139239
}
140240

241+
/**
242+
* Euclidean squared distance between two points in R2
243+
* @param x1 first x-coordinate
244+
* @param y1 first y-coordinate
245+
* @param x2 second x-coordinate
246+
* @param y2 second y-coordinate
247+
* @return euclidean squared distance between (x1, y1) and (x2, y2)
248+
*/
141249
public static float dist2(float x1, float y1, float x2, float y2) {
142250
float intervalX = x2 - x1;
143251
float intervalY = y2 - y1;
144252
float distance = (float)(Math.pow(intervalX, 2) + Math.pow(intervalY, 2));
145253
return distance;
146254
}
147255

256+
/**
257+
* Compute the angle (in radians) between two vectors
258+
* @param vector1 the first vector
259+
* @param vector2 the second vector
260+
* @return the angle between vector1 and vector2
261+
*/
148262
public static float angleBetween(JVector2 vector1, JVector2 vector2) { //Gives the angle in radians
149263
float topPart = dotProduct(vector1, vector2);
150264
float botPart = vector1.getMagnitude() * vector2.getMagnitude();

core/src/com/group/golf/math/MathLib.java

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
/**
77
* A class to hold static methods for Math purposes
8+
* @author Julian Marrades
9+
* @author Kaspar Kallast
10+
* @author Alexandros Chimonas
811
*/
912
public class MathLib {
1013

0 commit comments

Comments
 (0)