App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

LinearInt.java
Go to the documentation of this file.
1 package mhr.appcore.utils;
2
3 public class LinearInt {
4
5 protected LinearInt() {}
6
7 public static int[][] interpolate(int fromX, int fromY, int toX, int toY, double space) {
8 double dist = Math.sqrt((toX - fromX)*(toX - fromX) + (toY - fromY)*(toY - fromY));
9 double count = dist / space;
10
11 double dx = (toX - fromX) / (double) count;
12 double dy = (toY - fromY) / (double) count;
13 double dt = 1.0 / count;
14
15 int ptCount = (int) count + 1; // tohle je pocet intervalu, ergo krajni bod, ve finale se ten prvni stejne asi nebude kreslit
16
17 int[][] retVal = new int[2][ptCount];
18
19 double x = fromX;
20 double y = fromY;
21
22 for (int i = 0; i < ptCount; i++) {
23 retVal[0][i] = (int) Math.round(x);
24 x += dx;
25 retVal[1][i] = (int) Math.round(y);
26 y += dy;
27 }
28 return retVal;
29 }
30
31 }