From: Arne Vajhøj on 17 Jun 2010 20:38 On 16-06-2010 07:26, Lew wrote: > From time immemorial screen coordinates have been expressed from the > top-left corner. You will go through a lot of useless effort resisting > this. > > Take the world for what it is and don't fight to jam it into your > preconceptions. I would never assume that 0,0 is top left. I would read the docs to see if it is top left or bottom left or center or something else. Top left is by far the most common - probably an inheritage from hardcopy terminals. But common != guaranteed. Arne
From: Arne Vajhøj on 17 Jun 2010 20:39 On 16-06-2010 09:49, Patricia Shanahan wrote: > The least readable piece of C code I have ever seen was written by some > programmers who preferred Pascal, and used #define to make their C code > look a bit Pascal-ish. Even for someone fluent in both C and Pascal, it > was very confusing. You mean: #define begin { #define end } ? I have seen that too ! <various nasty words censored > Arne
From: Eustace on 19 Jun 2010 00:27 On 2010-06-17 10:42 John B. Matthews wrote: > In article <hvc94v$7ep$1(a)speranza.aioe.org>, > Eustace <emfril(a)gmail.ccom> wrote: > >> On 2010-06-16 11:21 Peter Duniho wrote: > [...] >>> Yes. Use a scaling transform on the Graphics or Graphics2D instance, >>> just as you've already used a translation transform. Scale the X >>> coordinates by 1.0, and the Y coordinates by -1.0. > [...] >> Many thanks, Pete. I would have actually been surprised if they was not >> a scale method. It works *almost* marvelously. The only thing I've found >> so far is that if you try: >> >> Arc2D.Double arc = new Arc2D.Double(0, 0, 100, 100, 0, 90, Arc2D.PIE); >> >> the angle opens *downwards* rather than *upwards* as the angles do in >> trigonometry. > > This may be a limitation of Arc2D itself, which specifies "that 45 > degrees always falls on the line from the center of the ellipse to the > upper right corner of the framing rectangle. > > <http://java.sun.com/javase/6/docs/api/java/awt/geom/Arc2D.html> Talking about conventions, the pixel by pixel way of drawing an ark does not give the same results as the Ard2D: .... setSize(width, height); .... Rectangle2D.Double pixel = new Rectangle2D.Double(0, 0, 1, 1); painter2D.translate(width/2, height/2); painter2D.setColor(Color.red); x = -100; y = -100; w = 200; h = 200; arc = new Arc2D.Double(x, y, w, h, 0, 90, Arc2D.Double.OPEN); painter2D.draw(arc); painter2D.setColor(Color.green); x = 0; y = 0; double x0 = x + w/2; double y0 = y - h/2; double r = 100; double q; for (int i = 0; i < 89; i++) { q = Math.toRadians(i); pixel.x = Math.sin(q) * r; pixel.y = Math.cos(q) * r; painter2D.fill(pixel); } For the second method to give the same arc it has to be: q = Math.toRadians(i + 90); (I am using variable q instead of theta, since q is the Latin letter representing the Greek theta in "Greeklish", that is writing Greek using the Latin alphabet.) So Java is following 2 contradicting conventions. I do not remember any such problems with Basic. If it had even crossed my mind that the setting of the axes might have been different in other languages, I would have spent some time investigating how different languages handle this before plunging into one, and it would have been one of the factors in my decision. Anyway, the decisive drawback against using scale(1.0, -1.0) is that if you then want to use painter2D.draw(String, x, y) the string appears in the right place but upside down. There may be ways to correct this, but would make programming more complicated than flowing with the flow, so that settles the issue. I will be checking the projection library (as well as your website). Thanks, emf -- The folk oratorios of Mikis Theodorakis https://files.nyu.edu/emf202/public/mt/oratorios.html
From: John B. Matthews on 19 Jun 2010 22:13 In article <hvhh02$vb5$1(a)speranza.aioe.org>, Eustace <emfril(a)gmail.ccom> wrote: > On 2010-06-17 10:42 John B. Matthews wrote: > > In article <hvc94v$7ep$1(a)speranza.aioe.org>, > > Eustace <emfril(a)gmail.ccom> wrote: > > > >> On 2010-06-16 11:21 Peter Duniho wrote: > > [...] > >>> Yes. Use a scaling transform on the Graphics or Graphics2D > >>> instance, just as you've already used a translation transform. > >>> Scale the X coordinates by 1.0, and the Y coordinates by -1.0. [Thoughtful arc implementation elided.] > Anyway, the decisive drawback against using > > scale(1.0, -1.0) > > is that if you then want to use > > painter2D.draw(String, x, y) > > the string appears in the right place but upside down. There may be ways > to correct this, but would make programming more complicated than > flowing with the flow, so that settles the issue. One can always preserve and restore the graphics transform: import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import javax.swing.JFrame; import javax.swing.JPanel; /** @author John B. Matthews */ public class SineTest extends JPanel implements Runnable { private static final int SIZE = 400; private AffineTransform at; public static void main(String[] args) { EventQueue.invokeLater(new SineTest()); } @Override public void run() { JFrame f = new JFrame("ArcTest"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(this); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); } public SineTest() { this.setPreferredSize(new Dimension(640, 480)); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); g2d.setColor(Color.gray); g2d.drawLine(w / 2, 0, w / 2, h); g2d.drawLine(0, h / 2, w, h / 2); at = g2d.getTransform(); g2d.translate(w / 2, h / 2); g2d.scale(1, -1); g2d.setColor(Color.blue); double r = SIZE / 2; double q = -Math.PI / 2; double d = Math.PI / 180d; int x1 = (int) Math.round(q * r); int y1 = (int) Math.round(Math.sin(q) * r); int x2, y2; for (int i = 0; i < 180; i++) { q += d; x2 = (int) Math.round(q * r); y2 = (int) Math.round(Math.sin(q) * r); g2d.drawLine(x1, y1, x2, y2); x1 = x2; y1 = y2; } g2d.setTransform(at); g2d.setColor(Color.blue); g2d.drawString("y = sin(x)", 100, 100); } } > I will be checking the projection library (as well as your website). Excellent! -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
From: Roedy Green on 21 Jun 2010 19:49 On Wed, 16 Jun 2010 04:08:24 -0400, Eustace <emfril(a)gmail.ccom> wrote, quoted or indirectly quoted someone who said : >(a) Get used to the y axis moving downwards. > >(b) Use rotation and learn to remember that y replaces x etc. > >(c) Use (b) and overwrite the constructors that use x, y, w, h. The most important thing is, no matter what you choose, document your convention. If you don't document this, it can confuse, or waste other people's time trying to figure out what you used. This is especially true if you change the convention at different stages of your computation. -- Roedy Green Canadian Mind Products http://mindprod.com There is no harm in being sometimes wrong especially if one is promptly found out. ~ John Maynard Keynes (born: 1883-06-05 died: 1946-04-21 at age: 62)
First
|
Prev
|
Pages: 1 2 3 Prev: How to pass a class as argument? Next: 5 Reasons why In-memory analysis matters |