Say I have a triangle made with 3 points.
makeTriangle(x1, y1, x2, y2, x3, y3);
How do I check if said triangle contains the a certain set of points?
I'm trying to make an interactive UI with P5.js that includes an arrow that allows you to resize the object. The wireframe code is:
let Size, x, y, moving;
//runs once at the start of the program
function setup() {
createCanvas(400, 400);
Size = 100;
x = 10;
y = 10;
moving = false;
}
//runs once every frame
function draw() {
background(220);
handleMouse();
fill("grey");
noStroke();
square(x, y, Size, 5);
fill("black");
triangle( x + Size * 0.9, y + Size * 0.9,
x + Size * 0.7, y + Size * 0.9,
x + Size * 0.9, y + Size * 0.7 );
}
function handleMouse(){
if(mouseInTriangle(/* x1, y1, x2, y2, x3, y3 */) && mouseIsPressed || mouseIsPressed && moving){
moving = true;
} else {
moving = false;
}
if(moving){
Size = max((mouseX + mouseY)/2 + x + y, 50);
}
}
function mouseInTriangle(x1, y1, x2, y2, x3, y3){
//Is mouse in triangle?
return true;
}
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.1/lib/p5.js"></script>
Is there a dynamic way to tell if a point is within a triangle?