not sure what this is, I think I was trying to figure out what a dot product is
Last active
April 3, 2021 15:31
-
-
Save jordanorelli/8994869 to your computer and use it in GitHub Desktop.
Dot product
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
PVector p1; | |
PVector p2; | |
PVector origin; | |
void setup() { | |
size(500, 500); | |
background(255); | |
origin = new PVector(width * 0.5, height * 0.5); | |
p1 = new PVector(0, height * -0.25); | |
p2 = new PVector(width * 0.25, 0); | |
} | |
void draw() { | |
background(255); | |
translate(origin.x, origin.y); | |
strokeWeight(4); | |
stroke(255, 0, 0); | |
line(0, 0, p1.x, p1.y); | |
stroke(0, 255, 0); | |
line(0, 0, p2.x, p2.y); | |
float p3 = PVector.dot(p1, p2); | |
fill(0); | |
textAlign(CENTER); | |
text(p3, 0, height * 0.25); | |
} | |
void mouseClicked() { | |
p2.x = mouseX - origin.x; | |
p2.y = mouseY - origin.y; | |
} | |
void mouseDragged() { | |
p2.x = mouseX - origin.x; | |
p2.y = mouseY - origin.y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a little math toy to illustrate the dot product between vectors. One vector is fixed while the other is affected by mouse control. Click and drag to move the second vector. The dot product of the two vectors is printed to the screen.