Graphics origin 
Author Message
 Graphics origin

In adding a graphics library to ANS Forth, should the vertical axis grow
down from the top left corner or up from the bottom left?

I am inclined to grow up from the bottom left corner. What are the pros
and cons?

--
Bye for now
                                         ____/  /  __  /   /   /   /   /
Chris Jakeman                           /      /  /  _/   /   /   /  /
                                       __/    /  / __    /   /   /_/
                                      /      /  /   /   /   /   /  \
                                   __/    __/  ____/    ___/ __/   _\

                           Forth Interest Group United Kingdom Chapter
Voice +44 (0)1733 753489   at www.users.zetnet.co.uk/aborigine/forth.htm



Sat, 17 Nov 2001 03:00:00 GMT  
 Graphics origin

Quote:
Chris writes:
> I am inclined to grow up from the bottom left corner. What are the pros
> and cons?

Con: most graphic system calls do "down".
Pro: it's natural for final use (IMHO). I use up in iForth.

The times I can remember it was really inconvenient to have "up" was
when copying a bitmap to the screen. Now the natural origin is leftup, not
leftdown.

If you're planning ahead carefully, you will probably have found the need of
a "world" coordinate transformation word. This word converts user scale
and origin to pixels. Especially when you plan for a floating-point
interface (given current hardware and standards like OpenGL not so strange a
choice), the transformation will prove to be used all of the time. So "up"
and "down" at the low level become unimportant, *unless* you intend to
manipulate lots of pixel-related data.

-marcel



Sun, 18 Nov 2001 03:00:00 GMT  
 Graphics origin

Quote:

> In adding a graphics library to ANS Forth, should the vertical axis grow
> down from the top left corner or up from the bottom left?

> I am inclined to grow up from the bottom left corner. What are the pros
> and cons?

If were doing it, I'd have the ability to output postscript source in
the back of my mind; and so would follow PostScript conventions as far
as possible.  That means growing up from the bottom left corner.

--David
 _  _________________________________________________________________
(_\(__
 _|__)  David N. Williams          Phone:  1-(734)-764-5236
__|___  University of Michigan     Fax:    1-(734)-763-2213

 \|     Ann Arbor, MI 48109-1120   Office: 3421 Randall Laboratory



Sun, 18 Nov 2001 03:00:00 GMT  
 Graphics origin

Quote:
Chris Jakeman  writes:
> In adding a graphics library to ANS Forth, should the vertical axis grow
> down from the top left corner or up from the bottom left?

> I am inclined to grow up from the bottom left corner. What are the pros
> and cons?

I agree and second Marcel's remarks. For the user the convention is
lower left corner = origin.

However, it would be best to provide the freedom to specify direction
and origin. Since the former can be done by vectoring in an extra NEGATE
it seems reasonable to include the words UPRIGHT and ~UPRIGHT to toggle
the directional convention. Origin gets set with a Standard 2CONSTANT,
XY-ORIGIN. I am, as always, open to suggestions for better names.

--
Julian V. Noble

"Elegance is for tailors!"    -- Ludwig Boltzmann



Sun, 18 Nov 2001 03:00:00 GMT  
 Graphics origin


Quote:
>In adding a graphics library to ANS Forth,

What is this going to include ?
Perhaps it is nice to have a standard way to plot a pixel somewhere.
On the other hand I would also like to get the benefits of DirectX.

Jos



Sun, 18 Nov 2001 03:00:00 GMT  
 Graphics origin

Quote:

>In adding a graphics library to ANS Forth, should the vertical axis grow
>down from the top left corner or up from the bottom left?

>I am inclined to grow up from the bottom left corner. What are the pros
>and cons?

There are two issues, screen coordinates and "world" or data coordinates.

Screen coodinates depend on your environment.  Windows and most graphics
displays have an origin upper left.  You had best comply at that layer.

World coordinates are totally dependent on the application.  You should let
your users define a world coordinate system giving its origin and size in
screen coordinates to specify a transformation.  Thereafter, the user works
in world coordinates and it works the way most natural to that particular
application.

We have done a lot of image processing and graphics.  polyFORTH had an
extensive graphics package.  If I have time in the next few days, I'll post
its documentation somewhere.

I also highly recommend that you specify vectors with x on top and y
beneath, because usually x changes faster and you'll minimize stack
thrashing.  Also, be sure and include a set of vector operators:  V+, V-,
V*/ (multiply a vector by a ratio of scalars), etc., preferably written in
assembler.

Cheers,
Elizabeth



Sun, 18 Nov 2001 03:00:00 GMT  
 Graphics origin

[..]

Quote:
> I also highly recommend that you specify vectors with x on top and y
> beneath, because usually x changes faster and you'll minimize stack
> thrashing.

I'm not ready to believe this without proof (a screen is wider than
it's tall, how's that for a start :-)

General graphics don't seem to favor horizontal over vertical. To make
a real difference the "y x-is-better-than-x y"  situation should occur
in loops. But in those cases, how difficult can it be to do ...
SWAP n 0 DO ...

With regards to stack trashing, we've been there before. Turtle graphics
can't be beaten for clarity (OK, "haven't.")

Quote:
>             Also, be sure and include a set of vector operators:  V+, V-,
> V*/ (multiply a vector by a ratio of scalars), etc., preferably written in
> assembler.

I've found these to be _occasionally_ a little bit useful, and only in
writing other graphics primitives. But of course it depends on the
applications one has in mind.

The Forth graphics I use most often are a tool to plot arbitrary functions
(SKETCH and SKETCH3D) and a tool to plot an X{ versus a Y{ array. Less
frequently used (cumbersome to set up) is a presentation quality plotter
(to printer, clipboard or screen) that allows labeled axes, descriptive
text, multi-views, multi-fonts. And of course turtle 2&3D graphics for
fast hacks.

-marcel



Mon, 19 Nov 2001 03:00:00 GMT  
 Graphics origin

Quote:
> In adding a graphics library to ANS Forth, should the vertical axis grow
> down from the top left corner or up from the bottom left?

Thanks to everyone who has posted on this, Marcel Hendrix, David
Williams, Julian Noble, Jos Ven, Elizabeth Rather and anyone else.

I'm writing to correct any mis-understandings here. I've read all the
postings about the value of libraries for Forth and I wouldn't want
anyone to go to any trouble in the belief that I am planning a major
ANS-compatible graphics library.

I should perhaps have written:
"In adding a few graphics words to allow a browser-applet Forth to use
the Java graphics functions"...

These would read and set colour and mode, draw lines and fill areas and
read pixels and the extent of drawing area. All drawing units would be
pixels.

I would love to see a capable graphics library established, but this
current project is taking all my spare enthusiasm and time. We'll be
going public fairly soon now.

--
Bye for now
                                         ____/  /  __  /   /   /   /   /
Chris Jakeman                           /      /  /  _/   /   /   /  /
                                       __/    /  / __    /   /   /_/
                                      /      /  /   /   /   /   /  \
                                   __/    __/  ____/    ___/ __/   _\

                           Forth Interest Group United Kingdom Chapter
Voice +44 (0)1733 753489   at www.users.zetnet.co.uk/aborigine/forth.htm



Mon, 19 Nov 2001 03:00:00 GMT  
 Graphics origin

Quote:
>General graphics don't seem to favor horizontal over vertical. To make
>a real difference the "y x-is-better-than-x y"  situation should occur
>in loops. But in those cases, how difficult can it be to do ...
>SWAP n 0 DO ...

        I actually find it better to keep Y in TOS.  Typically, it will
probably get pushed onto the return stack and accessed from there as a
constant "local variable".

-GJC



Tue, 20 Nov 2001 03:00:00 GMT  
 Graphics origin


Quote:

> Chris writes:

[snip]

> If you're planning ahead carefully, you will probably have found the
need of
> a "world" coordinate transformation word. This word converts user
scale
> and origin to pixels. Especially when you plan for a floating-point
> interface (given current hardware and standards like OpenGL not so

strange a
While you're at it, you could use a full matrix (3x3) of homogeneous
coordinates. This enables your library to include all transformations
(rotation, translation, shearing and scaling) with only one matrix by
vector multiplication displayed!!! pixel. If you do a lot of
transformations (e.g. rotating around a non-origin coordinate) this can
be computed in one matrix, giving you the same per-pixel time for
rot-move-rot-scale-shear-rot... as for a simple move.
The disadvantage is this: In cases you don't need the matrix (e.g. world
coordinates==screen coordinates) this adds a per-pixel time that is
unnessesary. You have to take care in this case (e.g. using a deferred
word, that does the computation from world to screen and set it to noop
on the identity matrix).
Quote:
> choice), the transformation will prove to be used all of the time. So
"up"
> and "down" at the low level become unimportant, *unless* you intend to
> manipulate lots of pixel-related data.

If you manipulate pixel-related data, manipulate them in an array of
pixel and THEN display them. That is more general.
Most operations on bitmaps are done in u,v (bitmap relative) coordinates
anyway. The only exception to this is faked lighting in 3D. This
includes u,v and z (the depth of the pixel) which requires projection,
lighting and last display.

A good source for such algorithms (2D and 3D) is
comp.graphics.algorithms.

--
Lars Krueger

URL:
http://homestead.dejanews.com/user.lars_krueger/

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.



Fri, 23 Nov 2001 03:00:00 GMT  
 Graphics origin

Quote:

>In adding a graphics library to ANS Forth, should the vertical axis grow
>down from the top left corner or up from the bottom left?

>I am inclined to grow up from the bottom left corner. What are the pros
>and cons?

Whatever. The difference is SOOOO SMALL, that you may choose whatever
you feel like. After all, you can go from one to the other by simply
subtracting Y from the vertical range (window height).

        ( Y -- Y')  YRANGE SWAP -

        Bart.



Mon, 26 Nov 2001 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. viewport origin vs. window origin

2. Fern's Graphic Library, Printing Graphics / Impresion de Graficos

3. Xlib 2d graphics or GL 3d graphics and tcl/tk

4. Java Origins in Objective-C and Smalltalk - by one of its authors

5. S-Plus, Origin or something else ? TRY J.

6. J and index-origin question.

7. Index Origin in GLEE

8. K.CoSy Edition 1 ( 0 origin ) now available

9. origin of arrays

10. Sun vs. IBM and the origins of Swing

11. APL problem - sorting a matrix without gagging in origin 0

12. Origin of right hand precedence in APL?

 

 
Powered by phpBB® Forum Software