Triangle Draw Method
Use a line algorithm to connect point A with point C, and in an outer loop, let point A wander towards point B with the same line algorithm and with the wandering coordinates, repeat drawing that line. You can probably also include a z delta with which is also incremented iteratively. For the line algorithm, just calculate two or three slopes for the delta change of each coordinate and set one slope to 1 after changing the two others proportionally so they are below 1. This is very important for drawing closed geometrical areas between connected mesh particles. Take a look at the Qt Elastic Nodes example and now imagine drawing triangles between the nodes after stretching this over a skeleton. As long as it will remain online
You should try using the Shape
s API.
Take a look at JPanel repaint from another class which is all about drawing triangles, look to the getPath
method for some ideas
You should also read up on GeneralPath & Drawing Arbitrary Shapes.
This method is much easy to apply AffineTransformations to
There is not a drawTriangle method neither in Graphics nor Graphics2D. You need to do it by yourself. You can draw three lines using the drawLine
method or use one these methods:
- drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
- drawPolygon(Polygon p)
- drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
These methods work with polygons. You may change the prefix draw
to fill
when you want to fill the polygon defined by the point set. I inserted the documentation links. Take a look to learn how to use them.
There is the GeneralPath class too. It can be used with Graphics2D, which is capable to draw Shapes. Take a look:
- http://docs.oracle.com/javase/tutorial/2d/geometry/arbitrary.html