-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.java
More file actions
150 lines (126 loc) · 4.1 KB
/
Copy pathUtil.java
File metadata and controls
150 lines (126 loc) · 4.1 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
package ptjava;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public class Util {
public static double INF = 1e9;
public static double EPS = 1e-9;
public static int swapInt(int... args) {
return args[0];
}
public static double swapDouble(double... args) {
return args[0];
}
public static double Radians(double degrees) {
return degrees * Math.PI / 180;
}
public static double Degrees(double radians) {
return radians * 180 / Math.PI;
}
public static Vector Cone(Vector direction, double theta, double u, double v, ThreadLocalRandom rand) {
if (theta < EPS) {
return direction;
}
theta = theta * (1 - (2 * Math.acos(u) / Math.PI));
var m1 = Math.sin(theta);
var m2 = Math.cos(theta);
var a = v * 2 * Math.PI;
var q = Vector.RandomUnitVector(rand);
var s = direction.Cross(q);
var t = direction.Cross(s);
var d = s.MulScalar(m1 * Math.cos(a))
.Add(t.MulScalar(m1 * Math.sin(a)))
.Add(direction.MulScalar(m2))
.Normalize();
return d;
}
static double Median(List<Double> a) {
int middle = a.size() / 2;
if (a.size() % 2 == 1) {
return a.get(middle);
} else {
return (a.get(middle - 1) + a.get(middle)) / 2.0;
}
}
double Median(double[] items) {
var n = items.length;
if (n == 0) {
return 0;
} else if (n % 2 == 1) {
return items[items.length / 2];
} else {
var a = items[items.length / 2 - 1];
var b = items[items.length / 2];
return (a + b) / 2;
}
}
public static double Fract(double x) {
double ret = x - (int) x;
return ret;
}
public static double Clamp(double x, double lo, double hi) {
if (x < lo) {
return lo;
}
if (x > hi) {
return hi;
}
return x;
}
public static int ClampInt(int x, int lo, int hi) {
if (x < lo) {
return lo;
}
if (x > hi) {
return hi;
}
return x;
}
static String NumberString(Double x) {
return x.toString();
}
double[] ParseFloats(String[] items) {
double[] result = new double[items.length];
for (int i = 0; i < items.length; i++) {
result[i] = Double.parseDouble(items[i]);
}
return result;
}
int[] ParseInts(String[] items) {
int[] result = new int[items.length];
for (int i = 0; i < items.length; i++) {
result[i] = Integer.parseInt(items[i]);
}
return result;
}
static String DurationString(Duration time) {
return "Current Duration" + time.toString();
}
static String RelativePath(String path1) {
Path filepath = Paths.get(path1);
return filepath.relativize(filepath).toString();
}
static String NumberString(double x) {
return Double.toString(x);
}
static double[] ParseFloats_(String[] items) {
double[] doublearray = Arrays.stream(items).mapToDouble(Double::parseDouble).toArray();
return doublearray;
}
static int[] ParseInts_(String[] items) {
int[] intarray = Arrays.stream(items).mapToInt(Integer::parseInt).toArray();
return intarray;
}
public static Mesh CreateBrick(int color) throws IOException
{
var material = Material.GlossyMaterial(Colour.HexColor(color), 1.3F, Radians(20));
var mesh = STL.Load("models/toybrick.stl", material);
mesh.SmoothNormalsThreshold(Radians(20));
mesh.FitInside(new Box(new Vector(), new Vector(2, 4, 10)), new Vector( 0, 0, 0 ));
return mesh;
}
}