I think I must be doing something completely wrong. What I want to achieve is a triangle that rotates to point at a dot. I started out by Using the formula angle = math.deg(atan2(y2-y1,x2-x1)), then when failing, I tried creating vec2s and using angle = math.deg(vec2a:angleBetween(vec2b)). Still not pointing correctly. Maybe I am doing my rotation wrong. I would appreciate any help getting this working. Please see code below, my intent was that the triangle should always point at the dot, regardless of the value of the parameters
function setup()
parameter("x1",100,600,100)
parameter("y1",100,600,100)
parameter("x2",100,600,400)
parameter("y2",100,600,400)
end
function draw()
vec2a = vec2(x1,y1)
vec2b = vec2(x2,y2)
myangle = vec2a:angleBetween(vec2b)
background(40, 40, 50)
strokeWidth(5)
stroke(0, 0, 0, 255)
--print the target to point at
ellipse(x1,y1,5,5)
pushMatrix()
--now I translate to where I want to draw my triangle
--then I rotate to the angle
--and draw
translate(x2,y2)
rotate(math.deg(myangle))
drawtriangle()
popMatrix()
end
function drawtriangle()
strokeWidth(8)
stroke(255, 255, 255, 255)
line(0,0,20,-60)
line(20,-60,-20,-60)
line(-20,-60,0,0)
end
Any tips appreciated, thanks.