From: Peter Duniho on 16 Jun 2010 11:21 Eustace wrote: > [...] > I would like to hear what the solution of experienced programmers is. I > tend to accept (a), hoping that after some time it will seem natural. > But is there a (d) option of reversing the direction of the y axis? 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. Don't forget to set it back to the original state when you're done drawing. As for whether this is a good idea or not, IMHO the warnings to just follow the existing conventions are over-cautious. I agree that manipulating the language itself to try to make it look like something else is a bad idea. But graphical coordinate systems are inherently transformable, and it's actually a very good idea to do so when the data is naturally in some coordinate system other than the default one. It is much better to transform the coordinate system in one place, and then just draw the data as it is, than to try to adjust all of the data for each drawing operation explicitly. If you are trying to do this just so that you can, for example, lay out controls in a different coordinate system than the default, then I would advise against it as others have (I doubt it would even work). But if this is just about the things that you are drawing yourself, it's not only not bad, it can actually be a good way to simplify the code. Pete
From: Lew on 16 Jun 2010 14:50 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. > Rene' Descartes wrote: > But even before such immemorial times, physicists and mathematicians are > used to coordinates starting in the bottom left corner. > On computer screens? I think not. Different domain of discourse, different rules. My degree is in mathematics, but I don't try to fight the standard for screen coordinates. I'm much happier that way. I recommend the same to you. Lew wrote: >> Take the world for what it is and don't fight to jam it into your >> preconceptions. > Rene' Descartes wrote: > And Y-flipping is something standard in every sensible graphics package. Circular reasoning. You're proving your point by calling the conclusion "sensible". > Usually one has some world coordinates, some "normalized device > coordinates" (NDC) and the raw device coordinates. Y-flipping is taken > care when passing from NDC to raw. > The OP is using libraries that work in terms of screen coordinates. Ergo, they must use screen coordinates. Y-flipping is not relevant. -- Lew
From: Eustace on 17 Jun 2010 00:42 On 2010-06-16 11:21 Peter Duniho wrote: > Eustace wrote: >> [...] >> I would like to hear what the solution of experienced programmers is. >> I tend to accept (a), hoping that after some time it will seem >> natural. But is there a (d) option of reversing the direction of the y >> axis? > > 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. > > Don't forget to set it back to the original state when you're done drawing. > > As for whether this is a good idea or not, IMHO the warnings to just > follow the existing conventions are over-cautious. > > I agree that manipulating the language itself to try to make it look > like something else is a bad idea. But graphical coordinate systems are > inherently transformable, and it's actually a very good idea to do so > when the data is naturally in some coordinate system other than the > default one. It is much better to transform the coordinate system in > one place, and then just draw the data as it is, than to try to adjust > all of the data for each drawing operation explicitly. > > If you are trying to do this just so that you can, for example, lay out > controls in a different coordinate system than the default, then I would > advise against it as others have (I doubt it would even work). But if > this is just about the things that you are drawing yourself, it's not > only not bad, it can actually be a good way to simplify the code. > > Pete 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. Let me may clear that I am neither a programmer nor a mathematician. 15-20 years ago, when I had just learned QBasic I wrote strictly for my own use a number of programs, the most complex of which would read the coastline coordinates of the continents and draw globes any way I wanted, along with doing a couple other specific things I wanted it to do, with heavy use, of course, or spherical trigonometry. The programs were sufficient for my needs at the time, and I postponed the inevitable, that is learning an advanced language, until 5 years ago when I audited 2 Java classes, working on them certainly much harder than any of my for credit classmates. Soon, however, afterwards I lost steam, perhaps realizing that the globe program was still far beyond my capabilities at the time. Then, last year my new Vista laptop finally relegated my old programs to the programming junkyard (where of course they are only useful for still valuable spare parts), and lately it seems I've caught once more programming fever :) and started reworking the *easier* of my old (graphics) programs. I am excited discovering Java's immense capabilities (think of it: compared with QBasic!) and I enjoy the learning that comes from hands-on experience. As for the globe program, that will have to wait a little. In QBasic I would always declare the screen coordinates as I wanted, often with (0, 0) at the center of the screen that is indicated for globes, and had never even occurred to me to opt *not* to have the y axis *always* move upwards. I fully understand that this is a convention, and now I soon have to decide on the issue. Your suggestion would have settled it if only there wasn't this little thing with the opening of the angles, and, I suspect, other repercussions coming later. So, I am sorry to say Monsieur Descartes, however much I admire your reasoning, I am on the brink of letting go and flow with the flow; except if, after setting scale(1.0, -1.0), there is an easy way to set the angles opening upwards like in trigonometry...? I doubt it, but I have to ask before going whichever way I will go. Eustace -- Date Calculator with all-purpose JS code https://files.nyu.edu/emf202/public/js/datecalc.html
From: Peter Duniho on 17 Jun 2010 01:14 Lew wrote: > 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. > > Rene' Descartes wrote: >> But even before such immemorial times, physicists and mathematicians are >> used to coordinates starting in the bottom left corner. > > On computer screens? I think not. Oh, come on Lew. Since anyone ever thought of using a coordinate system on a computer screen, some APIs have drawn from the bottom up while others from the top down. DIBSections on Windows are often bottom up, and at least one of the current Mac OS APIs puts the origin in the lower left corner. There is no "one right way" for computers. > Different domain of discourse, different rules. > > My degree is in mathematics, but I don't try to fight the standard for > screen coordinates. I'm much happier that way. I recommend the same > to you. I don't see any evidence anyone is trying to "fight" the API. The drawing API is specifically designed to allow transformation from one coordinate system to another. The GUI APIs, not so much. I'm not aware of a way to position Swing components, for example, in any coordinate system other than the "origin top-lef" one, unless one writes a complete transformation layer that goes between one's own GUI code and the Swing API (which IMHO would count as "fighting" the API). But that's not the topic here. > [...] > The OP is using libraries that work in terms of screen coordinates. > Ergo, they must use screen coordinates. Y-flipping is not relevant. The OP is using libraries that provide robust and reliable control of the coordinate system in use. They are free to draw using whatever coordinate system they want, including one where the Y axis is flipped relative to the default. Pete
From: John B. Matthews on 17 Jun 2010 10:42 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> > 15-20 years ago, when I had just learned QBasic I wrote strictly for my > own use a number of programs, the most complex of which would read the > coastline coordinates of the continents and draw globes any way I > wanted, along with doing a couple other specific things I wanted it to > do, with heavy use, of course, or spherical trigonometry. You may enjoy Jerry Huxtable's Globe Applet and map projection library, written in Java: <http://www.jhlabs.com/java/maps/proj/index.html> [...] -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: How to pass a class as argument? Next: 5 Reasons why In-memory analysis matters |