package com.haxademic.demo.math;

import com.haxademic.core.app.P;
import com.haxademic.core.app.PAppletHax;
import com.haxademic.core.draw.context.PG;

import processing.core.PVector;

public class Demo_PVector_tests
extends PAppletHax {
	public static void main(String args[]) { PAppletHax.main(Thread.currentThread().getStackTrace()[1].getClassName()); }
	
	protected PVector center;
	protected PVector mouse = new PVector();
	protected PVector perp = new PVector();
	
	public void setupFirstFrame() {
		background(0);
		center = new PVector(p.width/2, p.height/2);
	}
	
	public void drawApp() {
		p.background(0);
		p.stroke(255);
		PG.setDrawCenter(p);
		mouse.set(p.mouseXEase.value() * p.width, p.mouseYEase.value() * p.height);
		
		// line to mouse
		p.line(center.x, center.y, mouse.x, mouse.y);
		
		// get perpendicular location from mouse
		// from: https://twitter.com/mattdesl/status/1140218255069646848
		p.stroke(0, 255, 0);
		float perpLength = 70f + 20f * P.sin(p.frameCount * 0.03f);
		perp.set(mouse).sub(center).normalize();
		perp.set(-perp.y, perp.x);
		perp.mult(perpLength).add(mouse);
		p.line(mouse.x, mouse.y, perp.x, perp.y);
		p.ellipse(perp.x, perp.y, 10, 10);
	}
}

@@ -471,100 +471,462 @@
 %09%0A%09p
-ublic void setupFirstFrame() %7B%0A%09%09background(0);%0A%09%09center = new PVector(p.width/2, p.height/2
+rotected PVector%5B%5D lineSegments = new PVector%5B%5D %7B %0A%09%09%09new PVector(150, 100), %0A%09%09%09new PVector(100, 200), %0A%09%09%09new PVector(180, 240)%0A%09%7D;%0A%09protected PVector perp1 = new PVector();%0A%09protected PVector perp2 = new PVector();%0A%0A%09%0A%09public void setupFirstFrame() %7B%0A%09%09background(0);%0A%09%09center = new PVector(p.width/2, p.height/2);%0A%09%7D%0A%09%0A%09protected void getPerp(PVector p1, PVector p2, PVector pDest) %7B%0A%09%09pDest.set(p2).sub(p1).normalize();%0A%09%09pDest.set(-pDest.y, pDest.x
 );%0A%09
@@ -1548,13 +1548,779 @@
 0, 10);%0A
+%09%09%0A%09%09// average perpendiculars between line segments%0A%09%09for (int i = 0; i %3C lineSegments.length; i++) %7B%0A%09%09%09PVector point = lineSegments%5Bi%5D;%0A%09%09%09point.add(1.5f * P.sin(i + p.frameCount * 0.05f), 1.5f * P.cos(i + p.frameCount * 0.04f));%0A%09%09%09p.noStroke();%0A%09%09%09p.ellipse(point.x, point.y, 10, 10);%0A%09%09%09if(i %3E 0) %7B%0A%09%09%09%09PVector pointLast = lineSegments%5Bi-1%5D;%0A%09%09%09%09p.stroke(255);%0A%09%09%09%09p.line(point.x, point.y, pointLast.x, pointLast.y);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09getPerp(lineSegments%5B0%5D, lineSegments%5B1%5D, perp1);%0A%09%09getPerp(lineSegments%5B1%5D, lineSegments%5B2%5D, perp2);%0A%09%09perp1.lerp(perp2, 0.5f);%0A%09%09%0A%09%09// draw averaged perpendicular%0A%09%09perp1.mult(50).add(lineSegments%5B1%5D);%0A%09%09p.stroke(0, 255, 0);%0A%09%09p.line(lineSegments%5B1%5D.x, lineSegments%5B1%5D.y, perp1.x, perp1.y);%0A%09%09p.ellipse(perp1.x, perp1.y, 10, 10);%0A
 %09%7D%0A%7D%0A

Add averaged normal demo from PVector calcs