summaryrefslogtreecommitdiffstats
path: root/AutoVisual
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2016-01-02 03:49:20 +0100
committerDavid Runge <dave@sleepmap.de>2016-01-02 03:49:20 +0100
commit2f48fe13cbd130db75fc45d6853b8839d94e2a61 (patch)
tree428ab8972529a8d75d1f3febff60933cef182557 /AutoVisual
parent4c8c61a6241e4b1f92a35e92004d550474895644 (diff)
downloadprocessing-sketchbook-2f48fe13cbd130db75fc45d6853b8839d94e2a61.tar.gz
processing-sketchbook-2f48fe13cbd130db75fc45d6853b8839d94e2a61.tar.bz2
processing-sketchbook-2f48fe13cbd130db75fc45d6853b8839d94e2a61.tar.xz
processing-sketchbook-2f48fe13cbd130db75fc45d6853b8839d94e2a61.zip
AutoVisual/IGPFamily.pde: Adding functions for to find intersections
between lines (lineIntersections()), extend lines up until a given limit in one dimension (extendLine()) and to get the angle between two PVectors relative to the first one (angleBetweenTwoVectors()).
Diffstat (limited to 'AutoVisual')
-rw-r--r--AutoVisual/IGPFamily.pde37
1 files changed, 37 insertions, 0 deletions
diff --git a/AutoVisual/IGPFamily.pde b/AutoVisual/IGPFamily.pde
index 3108686..4d05542 100644
--- a/AutoVisual/IGPFamily.pde
+++ b/AutoVisual/IGPFamily.pde
@@ -164,6 +164,43 @@ class IGPFamily {
translate(mid.x*(-1), mid.y*(-1));
}
+ PVector lineIntersection(PVector p1, PVector p2, PVector p3, PVector p4) {
+ PVector b = PVector.sub(p2, p1);
+ PVector d = PVector.sub(p4, p3);
+
+ float b_dot_d_perp = b.x * d.y - b.y * d.x;
+ if (b_dot_d_perp == 0) {
+ return null;
+ }
+
+ PVector c = PVector.sub(p3, p1);
+ float t = (c.x * d.y - c.y * d.x) / b_dot_d_perp;
+ if (t < 0 || t > 1) { return null; }
+ float u = (c.x * b.y - c.y * b.x) / b_dot_d_perp;
+ if (u < 0 || u > 1) { return null; }
+
+ return new PVector(p1.x+t*b.x, p1.y+t*b.y);
+ }
+
+ float angleBetweenTwoVectors (PVector p1, PVector p2) {
+ float angle = atan2(p1.y-p2.y, p1.x-p2.x);
+ if (angle < 0) {
+ angle+=TWO_PI;
+ }
+ return degrees(angle);
+ }
+
+ PVector extendLine(PVector startPoint, PVector endPoint, float boundary, boolean vertical){
+ float m,n;
+ m = (endPoint.y-startPoint.y)/(endPoint.x-startPoint.x);
+ n = endPoint.y-m*endPoint.x;
+ if (vertical){
+ return new PVector((boundary-n)/m, boundary);
+ } else {
+ return new PVector(boundary, (m*boundary)+n);
+ }
+ }
+
void display() {
createAlphaCircle();
}