I have a fairly complex list of short line segments that taken together form a line.
I'd like to take this line and draw it 4 times along the 4 edges of a polygon. Obviously, for each side of the polygon I'll need to rotate the line by 90 degrees and translate it to it's final position.
After drawing this polygon with irregular sides I'd like to fill it.
I have the folowing code:
private void drawSide(GeneralPath path, int startX, int endX, int y)
{
path.moveTo(startX, y);
// in reality this is very complex, but for now, just draw a line
path.lineTo(endX, y);
}
private AffineTransform getTransform(int deltaX, int deltaY, int angle)
{
AffineTransform rat = new AffineTransform();
rat.translate(deltaX, deltaY);
rat.rotate(Math.toRadians(angle));
return rat;
}
private void test(Graphics2D g2d)
{
GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
drawSide(path, 100, 200, 100);
path.transform(getTransform(100, 0, 90));
drawSide(path, 100, 200, 100);
path.transform(getTransform(100, 100, 180));
drawSide(path, 100, 200, 100);
path.transform(getTransform(0, 10, 270));
drawSide(path, 100, 200, 100);
path.closePath();
g2d.fill(path);
g2d.draw(path);
}
I don't really understand what's wrong here. Can anyone help?
The first thing I want to point out is, I'm an idiot. So the first thing I try to do is find a workflow which my cognitive facilities can grasp.
What does this mean? There's probably a better solution, but I can't see it right now.
I did try doing a "local" context workflow, which would simply apply 90 degrees of rotation at each step, but that ended in a mess, so, I stuck with a "world context" workflow
This just means that the rotation/translations are based on the "world context" as apposed to the local context of the last change, yea for me
So, the basic idea is to start with a basic line
Path, then create a newPathfor each segment, appending the "base"Pathto and applying appropriate transformations, for exampleA "possible" local context...
This basically applies a transformation to an existing
Pathon each step. Because it's applying it to an existingPath, you need to keep in mind that you're rotation point is actually the start point of the line, which is something that just messes with my head