-
Notifications
You must be signed in to change notification settings - Fork 519
Expand file tree
/
Copy pathBezier.java
More file actions
executable file
·49 lines (41 loc) · 1.24 KB
/
Bezier.java
File metadata and controls
executable file
·49 lines (41 loc) · 1.24 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
package com.rssignaturecapture.utils;
public class Bezier {
public TimedPoint startPoint;
public TimedPoint control1;
public TimedPoint control2;
public TimedPoint endPoint;
public Bezier(TimedPoint startPoint, TimedPoint control1,
TimedPoint control2, TimedPoint endPoint) {
this.startPoint = startPoint;
this.control1 = control1;
this.control2 = control2;
this.endPoint = endPoint;
}
public float length() {
int steps = 10, length = 0;
int i;
float t;
double cx, cy, px = 0, py = 0, xdiff, ydiff;
for (i = 0; i <= steps; i++) {
t = i / steps;
cx = point(t, this.startPoint.x, this.control1.x,
this.control2.x, this.endPoint.x);
cy = point(t, this.startPoint.y, this.control1.y,
this.control2.y, this.endPoint.y);
if (i > 0) {
xdiff = cx - px;
ydiff = cy - py;
length += Math.sqrt(xdiff * xdiff + ydiff * ydiff);
}
px = cx;
py = cy;
}
return length;
}
public double point(float t, float start, float c1, float c2, float end) {
return start * (1.0 - t) * (1.0 - t) * (1.0 - t)
+ 3.0 * c1 * (1.0 - t) * (1.0 - t) * t
+ 3.0 * c2 * (1.0 - t) * t * t
+ end * t * t * t;
}
}