-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibMath.java
More file actions
318 lines (286 loc) · 9.37 KB
/
Copy pathLibMath.java
File metadata and controls
318 lines (286 loc) · 9.37 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/**
* This is a collection of formulas for dealing with numbers, simple operations,
* and geometrical shapes. LibMath is not limited to just Math, and also covers
* scientific operations that relate to numerical data.
*
* @author Norton
*/
public abstract class LibMath {
/**
* Takes the sum of the data in the array.
*
* @param the array containing the data
* @return the sum of all the data.
*/
public static double addAll(double[] data) {
double collector = 0.0;
for (int index = 0; index < data.length; index++) {
collector += data[index];
}
return collector;
}
/**
* Returns the square of the number in the parameter, but does not change
* it's value.
*
* @param the number to square.
* @return the squared number.
*/
public static double returnSquareOf(double number) {
return number * number;
}
/**
* Returns nothing but turns the parameter into a square of itself.
*
* @param the number to quare.
*/
public static void makeSquare(double number) {
number *= number;
}
/**
* Returns the mean for the list of data.
*
* @param Array containing the data.
* @return mean of the data.
*/
public static double getMean(double[] list) {
return (LibMath.addAll(list) / list.length);
}
/**
* Returns the standard deviation from a set of data. Standard deviation is
* commonly used in mathematics and the sciences to check the validity of
* the set of information. Conventions state that any point of data two
* standard deviations away from the mean should be rejected, and a new
* standard deviation calculated.
*
* @param list of data
* @return standard deviation.
*/
public static double calculateStandardDeviation(double[] list) {
if (list.length == 1) {
return list[0];
}
double[] localList = new double[list.length];
double collector = 0;
for (int index = 0; index < list.length; index++) {
localList[index] = list[index];
localList[index] -= LibMath.getMean(localList);
}
for (int index = 0; index < localList.length; index++) {
collector += LibMath.returnSquareOf(localList[index]);
}
return Math.sqrt(collector /= (localList.length - 1));
}
/**
* Returns the area of the specified rectangle. This can also be used with
* squares, just supply the same side twice.
*
* @param length
* @param width
* @return Area
*/
public static double rectangularArea(double length, double width) {
return (length * width);
}
/**
* Finds the volume of the rectangle with the specified length, width, and
* height. If you are trying to find the volume of a cube make all of the
* number the same. Volume is a measure of how much space the object
* occupies.
*
* @param length of the prism
* @param width of the prism
* @param height of the prism
* @return volume of the prism.
*/
public static double rectangularVolume(double length, double width, double height) {
return (length * width * height);
}
/**
* Returns the area of the triangle. To calculate the area multiply the base
* by .5 and multiply it with the height (1/2bh)
*
* @param base length
* @param height of the triangle
* @return area
*/
public static double triangularArea(double base, double height) {
return (base * height * .5);
}
/**
* Finds the volume that the pyramid takes up.
*
* @param Length of the base
* @param Height of the pyramid
* @return volume of the pyramid
*/
public static double pyramidVolume(double base, double height) {
return ((1 / 3) * base * height);
}
/**
* Returns the missing side of a right triangle. The two sides to use with
* this method are the hypotenuse and the side of the triangle that is not
* missing.
*
* @param hypotenuse side
* @param the non-missing leg.
* @return missingSide
*/
public static double pyThagSide(double hypotenuse, double side1) {
return Math.sqrt(LibMath.returnSquareOf(hypotenuse) - LibMath.returnSquareOf(side1));
}
/**
* Finds the length of the hypotenuse when given the length of both of the
* legs.
*
* @param leg A
* @param leg B
* @return hypotenuse
*/
public static double pyThagHypotenuse(double side1, double side2) {
return Math.sqrt(LibMath.returnSquareOf(side1) + LibMath.returnSquareOf(side2));
}
/**
* Finds the circumference (perimeter) of a circle using the radius. The
* radius is the length from the side of the circle to the center. To find
* it using diameter, divide diameter by 2.
*
* @param radius of the circle
* @return the circumference of the circle
*/
public static double circumference(double radius) {
return ((radius * 2) * Math.PI);
}
/**
* Returns the area of a circle when given the radius. The radius is the
* length from the side of the circle to the center. To find it using
* diameter, divide by 2.
*
* @param radius of the circle
* @return the Area of the circle.
*/
public static double circularArea(double radius) {
return (LibMath.returnSquareOf(radius) * Math.PI);
}
/**
* Finds the volume of the sphere with the specified radius. The volume is
* how much space the object occupies.
*
* @param radius of the sphere
* @return volume of the sphere.
*/
public static double sphericalVolume(double radius) {
return ((4 / 3) * Math.PI * (Math.pow(radius, 3)));
}
/**
* Returns the area of the cylinder with the specified radius and height.
*
* @param radius of the cylinder's circles.
* @param height of the cylinder
* @return area of the cylinder
*/
public static double cylindricalArea(double radius, double height) {
return (2 * Math.PI * radius * height) + (2 * LibMath.circularArea(radius));
}
/**
* Returns the volume that the cylinder takes up.
*
* @param radius of the cylinder's circles.
* @param height of the cylinder
* @return The volume of the cylinder.
*/
public static double cylindricalVolume(double radius, double height) {
return Math.PI * LibMath.returnSquareOf(radius) * height;
}
/**
* Returns the area of a cone when give the radius of it's base, the height
* of the cone, and the height of the cone's slant.
*
* @param The base's radius
* @param The height of the cone
* @param The height of the cone's slant
* @return The area of the cone.
*/
public static double coneArea(double radius, double height, double slant) {
return (Math.PI * slant * radius) + LibMath.circularArea(radius);
}
public static double coneVolume(double radius, double height) {
return (1 / 3) * LibMath.circularArea(radius) * height;
}
/**
* Returns the density of the object. Density is equal to the mass divided
* by volume.
*
* @param mass of the object
* @param volume of the object
* @return density of the object
*/
public static double densityOf(double mass, double volume) {
return mass / volume;
}
/**
* Converts the celcius temperature to fahrenheit
*
* @param The temperature in celcius
* @return The temperature in fahrenheit
*/
public static double convertCelciusToFahrenheit(double celcius) {
return celcius * (9 / 5) + 32;
}
/**
* Converts the fahrenheit temperature to celcius.
*
* @param the fahrenheit temperature
* @return the celcius temperature
*/
public static double convertFahrenheitToCelcius(double fahrenheit) {
return fahrenheit * (5 / 9) - 32;
}
/**
*Converts Fahrenheit to Kelvin.
*@param fahrenheit - The temperature in fahrenheit.
*/
public static double convertFahrenheitToKelvin(double fahrenheit) {
return LibMath.convertFahrenheitToCelcius(fahrenheit)-273.15;
}
/**
*Converts celcius to kelvin.
*@param celcius - The temperature in celcius.
*/
public static double convertCelciusToKelvin(double celcius){
return celcius-273.15;
}
/**
*Converts kelvin to Celcius.
*@param kelvin - The temperature in kelvin.
*/
public static double convertKelvinToCelcius(double kelvin){
return kelvin+273.15;
}
/**
*Converts kelvin to fahrenheit
*@param kelvin - The temperature in Kelvin
*/
public static double convertKelvinToFahrenheit(double kelvin)
{
return LibMath.convertCelciusToFahrenheit(convertKelvinToCelcius(kelvin));
}
/**
* Converts microseconds into regular seconds.
*
* @param microseconds - The time in micros
* @return the converted time in normal seconds.
*/
public static double microToSec(double microseconds) {
return microseconds / 1000 / 1000;
}
/**
* Converts the regular seconds into microseconds.
*
* @param seconds - The amount of time in seconds.
* @return the time in microseconds
*/
public static double secToMicro(double sec) {
return sec * 1000 * 1000;
}
}