We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello.
I have problem with finding angleBetween two vectors. Need to find angle A and angle B (you can see on the picture).
I have found angle A, but can`t get how find angle B.
Maybe someone can help?
function setup() {
createCanvas(700, 700);
}
function draw() {
background(155);
translate(350,350);
var v5 = createVector(-150,0);
var v6 = createVector(mouseX-500, mouseY-350);
var v7 = createVector(0,-150);
var v8 = createVector(mouseX-650, mouseY-350);
var angle3 = p5.Vector.angleBetween(v5,v6);
var angle4 = p5.Vector.angleBetween(v7,v8);
print(degrees(angle3),degrees(angle4));
stroke(255);
strokeWeight(5);
line(v5.x,v5.y,150,0);
line(150,0, mouseX-350, mouseY-350);
line(v5.x,v5.y,0,-150);
line(0,-150, mouseX-350, mouseY-350);
strokeWeight(10);
stroke(0,255,0);
point(v5.x,v5.y);
point(v6.x,v6.y);
point(v7.x,v7.y);
point(v8.x,v8.y);
}
Answers
I see you using
p5.Vector.angleBetween()
twice. What results are you getting? What results are you looking for instead?i think there was a thread recently that found that anglebetween was the angle between the origin and the two parameters.
in the above picture, the origin is on the horizontal white line directly below b. the mouse moves the top right point. v5 is the lower left point, v6 is 250 pixels left of the mousepointer for some reason, at B in this case.
I think I just have some problems with math in vector v8 coordinates, but still cant figure this out
FInally did it. Here is working version that prints in console two angles between vectors. Maybe someone can help find area of this figure?
Is it a trapezoid, or just a quadrilateral...? Do you know the formula for the area of either?
Can`t even tell. I think something like this will work https://mathsisfun.com/geometry/area-irregular-polygons.html