Repository navigation
Expand file tree
/
Copy pathCurvePoints.java
More file actions
71 lines (54 loc) · 1.55 KB
/
Copy pathCurvePoints.java
File metadata and controls
71 lines (54 loc) · 1.55 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
public class CurvePoints {
public static class point{
private final int x;
private final int y;
public point(int x,int y){
this.x=x;
this.y=y;
}
}
public static double dist(point p1,point p2){
return Math.sqrt( (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) );
}
public static double lengthOfCurve (point[] points){
double length=0;
for(int i=0;i<points.length-1;i++){
length+= dist(points[i],points[i+1]);
}
return length;
}
public static point pointAtOneFourth(point[] points){
double length= lengthOfCurve(points);
length/=4;
int x = 0 ,y = 0;
int i=0;
double seg=dist(points[i],points[i+1]);
while(seg<length){
i++;
seg=dist(points[i],points[i+1]);
length-=seg;
}
x= (int) (points[i].x + ( length*(points[i+1].x-points[i].x))/ seg);
y= (int) (points[i].y + ( length*(points[i+1].y-points[i].y))/ seg);
CurvePoints.point p= new CurvePoints.point(x,y);
return p;
}
public static point pointAtThreeFourth(point[] points){
double length= lengthOfCurve(points);
length/=4;
int x = 0 ,y = 0;
int i=points.length-1;
double seg=dist(points[i],points[i-1]);
while(seg<length){
i--;
seg=dist(points[i],points[i-1]);
length-=seg;
}
x= (int) (points[i].x + ( length*(points[i-1].x-points[i].x))/seg);
y= (int) (points[i].y + ( length*(points[i-1].y-points[i].y))/seg);
CurvePoints.point p= new CurvePoints.point(x,y);
return p;
}
public static void main(String[] args){
}
}