I’m trying to draw a triangle at the position which the user clicks on.
This is what I’ve done so far:
int[] xPoints = {(xPosition / 2), xPosition, (xPosition + (xPosition / 2))};
int[] yPoints = {(yPosition + yPosition), yPosition, (yPosition + yPosition)};
g.drawPolygon(xPoints, yPoints, 3);
The problem is that the size of the triangle varies depending on the xPosition and yPosition (these are taken from mouse coordinates).
Any ideas how I can just place a fixed size triangle at the specified X and Y coordinates?
Instead of using
xPosition / 2andyPositionfor the first and third points, use a fixed offset from thexPositionlike so:You can play around with the sizes, but if you want it to be equilateral, then
heightshould beMath.sqrt(3) * halfWidth.