java - Graphics and negative ordinate -
i want display points can have negative coordinates (x , y). now, points have negative x seem correctly displayed (ie. : @ left of points have positive x).
however, points have negative y displayed @ top of graph : exemple, point y = -5 displayed in top of point y = -3...
how can reverse graphics
' displaying ?
my (simple) code :
package general_classes; import javax.swing.*; import java.awt.*; import java.util.list; public class graph extends jframe { private list<storabledata> list_detected_points; private list<storabledata> list_all_points; private cupple barycenter; public graph(string title, list<storabledata> list_all_points, list<storabledata> list_detected_points) { double scaling_coef = 200; double move_x = 500, move_y = 500; this.add(new jpanel() { private graphics graphics; int x, y; private void drawpoint(cupple storable_data) { x = (int) (storable_data.getnumber(0) * scaling_coef + move_x); y = (int) (storable_data.getnumber(1) * scaling_coef + move_y); graphics.fillrect(x, y, 10, 10); graphics.drawstring(storable_data.tostring(), x - 5, y - 5); } @override public void paint(graphics graphics) { this.graphics = graphics; for(storabledata storable_data : list_all_points) { graphics.setcolor(color.white); this.drawpoint((cupple) storable_data); } if(list_detected_points != null) { (storabledata storable_data : list_detected_points) { graphics.setcolor(color.red); this.drawpoint((cupple) storable_data); } } } }); this.setvisible(true); } }
assuming receive points need draw, first find minimum , maximum coordinates on each dimension. this, can obtain scaling factor (using distance between min , max, , size of drawing box have) , offset (so min correspond 0 of draw box).
then create affinetransform
data above correctly convert each point when drawing it.
Comments
Post a Comment