I have this method to draw a triangle:
public void draw(Graphics g, int targetX, int targetY){
/*CODE TO ADJUST X AND Y*/
g.setColor(Color.white);
g.fillPolygon(new int[]{x - 4, x - 4, x + 9}, new int[]{y - 4, y + 4, y}, 3);
}
x and y are instance variables that reflect the centre point of the triangle and the triangle is drawn around this point. It's an isosceles triangle so that it's 'pointing' at something. With the parameters I use there it's pointing directly to the right.
targetX and targetY are the point that the triangle is moving towards. With each repaint x and y are incremented or decremented to move them towards the targets.
So what I'd like to do is draw the triangle so that it's pointing towards the target co-ordinates. With the approach I have right now I guess I would need to write a function that fills in the 'x - 4' 'x - 9', etc... calculations in the fillPolygon parameter with values that set the triangle in the right direction but I'm not really the best maths guy and so I have no idea what calculations such a function might need to contain.
I'm also pretty new to Swing so I have no idea whether my approach to drawing these triangles and moving them towards a certain point is even a good one so if anybody has any suggestions then I am all ears!
Any help with this would be much appreciated.