Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Last active April 3, 2021 15:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordanorelli/8994869 to your computer and use it in GitHub Desktop.
Save jordanorelli/8994869 to your computer and use it in GitHub Desktop.
Dot product

not sure what this is, I think I was trying to figure out what a dot product is

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;
}
@jordanorelli
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment