Last active
November 10, 2016 04:16
-
-
Save RollMan/c7e643e9dae16ca0670b5f3909bbb46e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.LinkedList; | |
| import java.util.Iterator; | |
| import java.lang.Math; | |
| public class Dev{ | |
| private static final float INF = 100000; | |
| private float max_x, min_x; | |
| private float max_y, min_y; | |
| private float major_len; | |
| private float minor_len; | |
| private Point major_point; | |
| private Point minor_point; | |
| private float angle; | |
| public Dev(){ | |
| max_x = max_y = 0; | |
| min_x = min_y = INF; | |
| offset_x = offset_y = 0; | |
| major_len = 0; | |
| minor_len = INF; | |
| major_point = new Point(0, 0); | |
| minor_point = new Point(0, 0); | |
| angle = 0; | |
| } | |
| public Point update(float x, float y){ | |
| float offset_x, offset_y; | |
| float radius; | |
| Point res = new Point(0, 0); | |
| float theta; | |
| //offset | |
| max_x = Math.max(max_x, x); | |
| min_x = Math.min(min_x, x); | |
| max_y = Math.max(max_y, y); | |
| min_y = Math.min(min_y, y); | |
| offset_x = min_x + (max_x - min_x) / 2; | |
| offset_y = min_y + (max_y - min_y) / 2; | |
| x -= offset_x; y -= offset_y; | |
| res.x = x; res.y = y; | |
| //distortion | |
| radius = Math.sqrt(x*x + y*y); | |
| if(radius > major_len){ | |
| major_len = raduis; | |
| major_point = new Point(x, y); | |
| } | |
| if(radius < minor_len){ | |
| minor_len = radius; | |
| minor_point = new Point(x, y); | |
| } | |
| theta = Math.atan(y/x); | |
| res.x = major_len * Math.cos(theta + atan(minor_point.y / minor_point.x)); | |
| res.y = minor_len / minor_len * Math.sin(theta + atan(minor_point.y / minor.point.x)); | |
| return res; | |
| } | |
| }; | |
| public class Point{ | |
| private float x; | |
| private float y; | |
| Point(float x, float y){ this.x = x; this.y = y;} | |
| }; | |
| Point PolarToCartesian(float radius, float theta, float originX, float originY){ | |
| Point res = new Point(0.0, 0.0); | |
| res.x = radius*cos(theta) + originX; | |
| res.y = radius*sin(theta) + originY; | |
| return res; | |
| } | |
| void drawPolygonOutline(LinkedList<Point> v){ | |
| beginShape(); | |
| for(Iterator<Point> it = v.iterator(); it.hasNext(); ){ | |
| Point p = it.next(); | |
| vertex(p.x, p.y); | |
| } | |
| endShape(CLOSE); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment