Computer Graphics Tools

updated 2009-04-29.

This is just something I threw together that I thought you might find useful. Comments?

This page is about the process of creating graphics to display on a computer screen.

related pages:

The comp.graphics.* series of newsgroups...

Standard art tools

Computer graphics tools intended to be used by graphic artists to create art.

how I scan photos

After a little experimentation, here's how I scanned photos last time.

photo scanning

There's probably a better way ...

  1. Put photo on scanner. If one edge of the photo has no detail (will be cropped off later), press it against one edge of the bed to help align the photo.
  2. In Paint Shop Pro, choose File | Import | Twain | Acquire... This starts up HP PrecisionScan LTX.

    The 2 adjustment dialogs should already be open; if not, open them with Tools | Exposure Adjustment and Tools | Color Adjustment.

    (these settings should already be enabled: Output type: Best Color Photograph (16 Mcolors). Output size: original size. Resolution: automatic (I think this is 200 dpi). Sharpen detail in photos (?). Use Maximum bit depth. )

  3. In HP PrecisionScan LTX, drag a box just slightly larger than the photograph. (it's not critical exactly how much larger this crop box is).
  4. In the Exposure Adjustment dialog, click Auto. (Perhaps picking the darkest black and the brightest white with the eyedropper would be better ?).
  5. The photos I'm scanning today were a bit reddish so I click on the cyan and blue triangles to get x = -20, y=-10. (in the Color Adjustment dialog box).
  6. ``Send the scan now'' button.

    I chose the numbers in the previous step to make neutral gray look neutral gray.

    Since I'm scanning a black and white photo, in theory I should be able to pick *any* pixel with the eyedropper and see that the R,G,B values are all equal to each other.

    When I keep the scanner default of x=0, y=0, the Red value is always larger (in the Paint Shop Pro histogram, I see peaks in the red shifted to the right (brighter) than the green and blue peaks.)

    You can tell when this is adjusted correctly by going to ``Tools | Exposure Adjustment'' and picking pixels with the eyedropper. The R,G,B values of *neutral* pixels (in particular, light and medium gray) in the photograph, (say, a white fencepost in the shade, or teeth...) should be very close to each other -- 127, 122, 131 are close enough.

    (it's best to do the previous 2 adjustments here, where the scanner does them with full 36 bit accuracy, rather than trying to do it later in 24 bit mode where we've already lost that information).

  7. In Paint Shop Pro, choose ``View | Image Information... | Creator Information''.
  8. Take the photo out of the scanner, look for anything written on the back. Type *all* that information into the ``Creator Information'' area: the year and day the photo was taken, who the photographer was, the names of all the people in the picture, where the picture was taken, etc.
  9. Rotate the photo right-side-up.
  10. Make up a name for the photo. Save *2* copies of the photo in .png format: the ``original'' with ``_raw.png'' suffix, and the ``working version'' with just the ``.png'' suffix.
  11. If this is a black-and-white original, do ``Colors | Grey scale''.
  12. Crop the photo. At minimum, crop the remaining white border (from step 3). Usually you'll want to crop a lot more than that to focus on the interesting areas.
  13. Save.
  14. Try to get rid of the annoying speckle pattern (which also helps compress the file much smaller). Image | Noise | Median Cut. If that destroys too many details, Ctrl+Z Undo, and try Image | Blur | Gaussian blur... | Radius: 0.5 pixels. | OK.
  15. Image | Resize | Percentage | 50% to try to get image roughly 400 pixels wide (web quality -- see #photo_size ).
  16. Save.
  17. Save with ``_thumbnail.png'' suffix. Crop even more stuff, then reduce to about 128 pixels in the long direction.
  18. Save.
  19. Consider converting from .png to .jpg.

See

for more scan tips.

Interactive Graphics Renderer (IGR)

[FIXME]

web art tools, preparing photos for the web

Specialized tools aimed at taking the art (generally created by one of the above Standard art tools ) and making it more suitable for the Web: reducing its bandwidth without significantly changing its appearance, making buttons out of it, etc.

See html.html#design_advice for more general layout design advice.

how big should I make my thumbnails ? Full-size web photos ?

[This is just a local backup copy; the live version of the "photo size" section has moved to http://visual.wiki.taoriver.net/moin.cgi/PhotoSize ]

Summary:

Web sizes are always in terms of pixels. People recommend many different sizes.

Thumbnails:

64x64
75 wide
80x80
80x80
100x150
128x128
128 wide
150x115
150 wide
192x192
192x128
260x175

"Try not to exceed 100 KB per web page for the total of all images"

Full-size web photos:

"under 420 pixels wide"
560 wide
600x400
600x400
750x500
760 wide

"twice the width of the finest significant line in a document"
"30 to 100 KB per image"
"make the smallest lowercase letter echo (e) 8 pixels high"

Full-size printed photos:

medium quality: approximately 150 pixels per inch of resolution
professional quality: at least 300 pixels per inch of resolution

fonts and typography

[This is just a local backup copy; the live version of the "fonts and typography" section has moved to http://visual.wiki.taoriver.net/moin.cgi/FontsAndTypography ]

tools for making letters shaped however you want; ideas for different letter styles, legibility, etc; fonts other have created using those tools and ideas.

The latest font news is at http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&group=comp.fonts and http://fonts.deviantart.com/ and http://en.wikipedia.org/wiki/Category:Digital_typography .

see also ASCII_Art fonts.

see also linux.html#tex for info on TeX, the standard way of typesetting mathematical equations.

see also si_metric_faq.html#iso8859 for some information on the default character set for web pages.

Some of these font try to make English text even easier to read, by making the letters more distinct. Others try to ``look cool'' or ``look pretty'' even if it makes English text slightly more difficult to read. See idea_space.html#alphabet_aesthetics for fonts that go to extremes to look cool, even if it makes English text almost impossible to read.

PostScript

[this is an old archive -- moved to http://visual.wiki.taoriver.net/moin.cgi/PostScriptLinks ] PostScript: it's not just a file format. Don Lancaster suggests using it as a full-fledged programming language in its own right.

http://www.cappella.demon.co.uk/ points to a cute little PostScript barcode utility and documentation.

Thinking in PostScript book by Glenn Reid http://rightbrain.com/pages/book-download.shtml online book [FIXME: to read] [Is this related to Thinking in C++ by Bruce Eckel ?]

http://cuisg11.unige.ch/OSG/people/jvitek/Compilers/Year93/msg00128.html PDB -- ANSI-C to PostScript translator/compiler apparently by Arthur van Hoff (Jan 1993)

fractals

see also Fractal Image compression

(FIXME: Consider moving to http://en.wikipedia.org/wiki/Fractal )

ASCII Art

graphics produced under severe limitations

David Cary is fascinated by ASCII Art. (consider moving to http://en.wikipedia.org/wiki/ASCII_art or http://visual.wiki.taoriver.net/moin.cgi/AsciiArt )

Visualization tools (and Math software)

Computer graphics tools intended to be used by doctrors, engineers, mathematicians, etc. to look into large data sets to "see" new insights.

see computer_architecture.html#cellular_automata for cellular automata simulators (some of them quite pretty).

see data_compression.html#benchmark for some medical images and other test images for these visualization tools.

see nanotech.html#molecule_modeling for tools for visualizing atoms and molecules.

VRML (Virtual Reality Modeling Language)

Graphics file formats and parsers

(and a couple of formatted text formats)

See also Writing Computer Graphics Software

see also data_compression.html#file_formats

"my favorite (standard) file formats"

Some other interesting and/or popular image formats:

general Information on file formats

detailed information on a few file formats I find interesting:

Books on Computer Graphics

These books on computer graphics are gnerally about "how to write software that generates computer graphics" or "how to write software that can read and write computer graphics files", not "how to draw art using your computer".

From: kallianp@cs.sc.edu (Mohit Kallianpur)
Newsgroups: comp.graphics.algorithms
Subject: Re: BOOKS
Date: 11 Oct 1995 18:44:29 GMT
Organization: University of South Carolina - Columbia - Computer Science
Lines: 76

cho <w-cho@ux4.cso.uiuc.edu> writes:

>	Hello.  I've just started out my study in computer graphics, and been
>searching for "a few good books." :)  I am fairly competent with C and
>C++...   I would appreciate any recommendation for books regarding 3D
>graphics.  Thank you!

Hi John,

    Check out http://wcl-rs.bham.ac.uk/GamesDomain/gamedev/3dbooks.html
In case you cannot check out that site, here is a list of books which
you may find very useful :

For Graphics intro and algorithms :

1)  3D Computer Graphics, 2nd Ed., Alan Watt, Addison-Wesley 1993,
    ISBN : 0-201-63186-5.

    This book should be owned by any person who is into Computer Graphics.
    Really excellent book!

2)  Computer Graphics: Principles and Practice (2nd Ed.) - J.D. Foley,
    A. van Dam, S.K. Feinder, J.F. Hughes, Addison- Wesley 1990,
    ISBN : 0-201-12110-7

    Another classic.
    There is an "Introduction to Computer Graphics" by the same authors. It is
    supposedly an abridged and modified version of the above book with code in
    "C". I have not looked at this book yet.

3)  Computer Graphics: A Programming Approach, 2nd Ed., Steven Harrington,
    McGraw-Hill 1987,
    ISBN : 0-07- 026753-7

4)  Advanced Animation and Rendering Techniques, Alan Watt and Mark Watt,
    Addison-Wesley,
    ISBN : 0-201- 54412-1

For the math part of graphics :

1)  Mathematical Elements for Computer Graphics, 2nd Ed. - David F. Rogers and
    J. Alan Adams, McGraw-Hill 1990,
    ISBN 0-07-053530-2

    Covers all the basic math stuff needed for graphics - including curves,
    splines, NURBS etc.

2)  Computer Graphics : An Introduction to Mathematics and Geometry,
    M. E. Mortenson, Industrial Press,
    ISBN : 0831111828.

    Apparently requires a good math background to read, as it is not easy reading.

For texturing, writing shaders etc. :

1)  Texturing and Modeling : A Procedural Approach, Ken Musgrave, David S. Ebert,
    Darwyn Peachey et. al., Academic Press Professional.
    ISBN : 0-12- 228760-6

For image processing :

1)  Digital Image Processing - Rafael C. Gonzalez and Richard E. Woods
    Addison-Wesley 1992,
    ISBN 0-201-50803- 6

    Excellent book on image processing!


    You can probably also get the Graphics Gems series from your library, and the
    source for it off the net.


    Hope this helps.

Mohit Kallianpur
(kallianp@cs.sc.edu)

Writing Computer Graphics Software

See also

You may also want to check out my style_guides [FIXME:] for related information.

Bresenham

[moved to http://visual.wiki.taoriver.net/moin.cgi/GraphicAlgorithm ]

Detailed information on the Bresenham algorithm. The original version was just for lines (on a mechanical pen-plotter). Since then, people have discovered/invented very similar algorithms for Bezier curves, circles, ellipses, etc.

The Bresenham algorithm is usually implemented in assembly language .

Bresenham lines

Bresenham Bezier curves

DAV: The ``addition only'' differencing is close to what I would call a modified Bresenham algorithm. Unfortunately it does not step 1 pixel per iteration like the circle algorithm, but instead jumps along and relys on a seperate line-draw algorithm to fill in the pixels. It looks something like ../program/bezier.c

other Bresenham curves

calligraphy

calligraphy [ Here we have manual, handmade graphics. Not computer graphics. Is there a better place to put this ? Related to `` typography '' here.] calligraphic works.

Unsorted computer graphics tools

Cool "Plant Evolution" software. http://www.ugcs.caltech.edu/~mattduke/final.html

http://www.baddesigns.com/ dedicated to spotlighting particularly poor examples of product and system design. maintained by Mike Darnell, a software usability expert with Netscape.

The Ultimate Animated GIF Site is located at : http://homepages.ihug.co.nz/~gbiggs/

Visio http://www.visio.com/

?? http://www.cerious.com/

Computer Graphics Format links http://www2.ncsu.edu/bae/people/faculty/walker/hotlist/graphics.html

Ghostscript includes output drivers that can produce JPEG (JFIF) files from Postscript images. *Please note* that JPEG is designed for continuous-tone images (such as photographs) and is therefore quite unsuitable for the vast majority of page images produced with Postscript. If you get crummy-looking JPEG files, don't blame Ghostscript; instead consult a reference about uses and abuses of JPEG, such as the JPEG FAQ available at http://www.faqs.org/faqs/jpeg-faq/.

-- Ghostscript "devices.txt"

Signal and Image Processing Institute of the University of Southern California http://sipi.usc.edu/recentre.html Biomedical Imaging Image and Video Compression

Graphics File Format Standards http://www.ora.com/centers/gff/specs.htm

http://www.jpeg.org/ home site of the JPEG and JBIG committees

http://www.u-aizu.ac.jp/brochure/SW/pasko.html member of FreeDesigner (CAD) mailing list; interesting related stuff.

the Virtual Environments, 3D Medical Imaging, and Computer Graphics Laboratory http://www.afit.af.mil/Schools/EN/graphics/GRAPHICS.html in the Air Force Institute of Technology's Graduate School of Engineering

Terrains http://www.cms.dmu.ac.uk/People/cph/VRbib/Terrain/ including a explaination of the "Mars" demo, and some publicly available terrain archives (Alaska ?).

http://www-gscit.fcit.monash.edu.au/~chesterk/vr/irvrnew.html long list of Virtual Reality resources, including mailing lists, web pages, books, etc.

Sci.virtual-worlds is a USENET newsgroup http://www.hitl.washington.edu/scivw/

Vector Rotations around Arbitrary Vector http://cadd.cern.ch/cad_geant_int/ddt_long/node14.html

Nigel Thompson http://www.thompson-ind.com/ has information on Win95 Game Programming (Direct 3D and other low-level graphics programming); Ham Radio Software; Stillwater Elementary online. /* was http://ourworld.compuserve.com/homepages/nigelt/ */

Very large "digital textile printer" http://www.encad.com/ prints images on fabric large enough to upholster sofas

Duggal Color Projects Inc. http://www.duggal.com/ very large digital printers: prints directly on NYC busses, building murals, cotton fabrics, owns a "giant inkjet mural printer (spray jet)"

http://www.jpg.com/ You can compress your images online with the "JPEG Wizard" (takes your JPEG images, and shrinks them further); webcam software; Medical imaging; ...

The Association for Information and Image Management (AIIM) International http://www.aiim.org/


Subject: ANNOUNCE: Free Radiosity Software (inc. C++ source code)
From:  (Ian Ashdown)
Date: Sat, 17 Feb 1996 17:18:38 GMT

The C++ source code for HELIOS, a fully-functional radiosity
renderer for MS-Windows 3.1, is now available for downloading
on the 'net ...

"Radiosity" is a computer graphics technique that enables you to
synthesize photorealistic images. Whereas ray tracing techniques
excel in the rendition of point light sources, specular
reflections, and refraction effects, radiosity methods accurately
model area light sources, diffuse reflections, color bleeding
between surfaces, and detailed shading within shadows. They are
in a sense complementary approaches to photorealistic rendering.

Folklore had it that you needed a graphics workstation with
gigabytes of RAM or even a supercomputer to do radiosity
rendering. This is no longer true: You can use your personal
desktop computer -- a '386 IBM-PC with a math coprocessor, 4 MB
of RAM, and a 256-color SVGA display will do nicely -- to
experiment with radiosity methods. A 66-MHz '486DX machine will
render a simple scene (540 polygons) in less than three minutes.
A more complex scene with 2,700 polygons can be rendered in a
little over six minutes.

Commercial radiosity renderers are slowly making their way into
the marketplace. Take a look, for example, at the incomparable
Lightscape Visualization system (http://www.lightscape.com) to
see what is available now for Windows NT. (Other interesting
sites on the Web for commercial radiosity renderers are
http://www.bentley.com/products/masterpiece.html -- download the
Microstation MasterPiece Technical Profile -- and the Italian
http://www.atma.it/english/rlight.html.)

In the meantime, you can download HELIOS to experiment with the
possibilities of radiosity rendering using MS-Windows 3.1 or
Windows 95. The Web site is:

  http://www.ledalite.com/lighthouse.html

where you will find a demonstration version of HELIOS Version
1.02C (106 KB) and the complete C++ development package (806 KB),
including four different executable versions of HELIOS, fully-
commented C++ source code (over 12,700 lines), make files for
Microsoft Visual C++ 1.5 and Borland C++ 4.5, online help files,
two demonstration environments, demo images, and more.

(While you are perusing our Web site, you might want to look at
http://www.ledalite.com/library/ledapub.html -- we have an
eclectic variety of academic papers and articles on computer
graphics and related topics available online for downloading.)

The HELIOS development package is *not* in the public domain. It
is copyrighted material that may be freely copied, redistributed,
and/or modified for personal, non-commercial use ONLY, provided
the copyright notice is included with all source code files.

HELIOS was first developed in:

  Ashdown, I. 1994. Radiosity: A Programmer's Perspective. New
  York, NY: John Wiley & Sons, Inc. Softcover, 498 pages, 12
  color plates.

  ISBN 0-471-30444-1 (without diskette)                $39.95 US
  ISBN 0-471-30488-3 (with 3.5-inch MS-DOS diskette)   $54.95 US

This book provides a detailed explanation of radiosity theory and
its associated algorithms (no knowledge of higher mathematics
required!) More important, it also includes complete, fully
documented, and compiler-independent C++ source code (over 7,500
lines) for HELIOS Version 1.00A, a fully-functional radiosity-
based rendering program for MS-Windows 3.1, Windows 95, and
Windows NT.

The radiosity-related code presented in the book is identical to
that now offered online. If you want to fully understand how
HELIOS (and radiosity) works, you more or less need to buy the
book.

You can order "Radiosity: A Programmer's Perspective" from your
local bookseller or (in the United States) directly from John
Wiley & Sons by calling 1-800-CALL-WILEY. You can also order the
book online from http://www.wiley.com.


Ian Ashdown, P. Eng.                 |             READ THE BOOK!
Research & Development Manager       |  Radiosity: A Programmer's Perspective
Ledalite Architectural Products Inc. |             by Ian Ashdown
                                     |         John Wiley & Sons, 1994
Visit http://www.ledalite.com        |      (Sneaky Internet Advertising)



###

Subject: Re: Swarm algorithm ...
From:  (Frank Compagner)
Date: 9 Feb 1996 14:02:53 GMT

...  says...
>I am looking for a Swarm algorithm, a la XSwarm.  All of the code I can find
>that implements this cool piece of eye candy is uncommented and contains a
>lot of picky little windowing commands for either X or MS-Windoze.
>
>I'd like to understand the mathematics behind it ...
>If anyone can help, or suggest further research options, I would appreciate
>it.
>
>Thanx
>RichD

Some time ago, in response to a very similar question, i wrote a little
(pascal) program that uses the same algorithm as the Xswarm screensaver. It's
a lot easier to understand. Someone else (can't seem to find who exactly,
maybe ) then converted this to C. I've got source and
executables to both, just tell me what you'd like to have and i'll mail them
to you.

Frank
------------------------------------------------------------------------------
Frank Compagner                           University of Amsterdam






###

Subject: Re: Bresenham or Fixed point ?
From: Illusion/Phoenix 
Date: Thu, 08 Feb 1996 12:58:54 +0100

jp wrote:
>
> Yves Dufournaud  wrote:
>
> >After all this good stuff on fixed point calculation,
> >I've a question :
> >to do bloc stretching you use :
> >- a derivative of bresenham ( as can be found in graphics gem) ?
> >- a fixed point algorithm ?
> >- none of these ? ( what do you use in this case ?)
>
> >Which one is the faster ?
>
> Well, this is just me, so don't take anything I say as fact or
> anything....but I have found Bresenhams alg. to be faster with long
> lines, and fixed-point to be real good for short lines......


In fact, it's really the opposite!
I'll explain why:

Bresenham could be optimized downto
a loop (unrolled or not) that is, let's
say 7 clock cycles. Fair enough.
It doesn't have much of a setup, though,
we can estimate it to 5 clock cycles.

I'm being reeeeally nice to you Bresenham folks,
in case you didn't you don't noticed.
I don't think anyone can make it THAT fast.

DDA, however, has a loop of basically
2-3 clockcycles fully optimized, per
pixel. This is in the best case, and
not for all slopes. With slopes closing to
the horizontal axis, it requires a bit more,
maybe something like 5-9 clock cycles.
This averages to 5 cc per pixel.
DDA have to use a DIV in the setup, and some
other things have to be done, so we can estimate
the setup time to 50 clock cycles.

Well, look here. This is a table of estimated
performance of both Bresenham and DDA. The scale
is one pixel per char on the vertical axis,
and 5 clock cycles per char on the horizontal one.

Now we have two equations, b(t) and d(t), where
b(t) shows how far the Bresenham routine has drawn
after a certain amount of time, and d(t), which
does the same for DDA.

b(t) = 1/7*t-5/7
d(t) = 1/5*t-50/5              , t >= 0

Let's calculate the point t where the two routines has
calculated the same amount of pixels.

1/7*t-5/7 = 1/5*t-50/5
 50/5-5/7 = 1/5*t-1/7*t
        t = (50/5-5/7)/(1/5-1/7)
        t = 162.5 clock cycles

At that point, both routines have drawn 22.5 pixels
From this we can see that for lines not longer
than 22 pixels, would be calculated faster with
Bresenham.

But if you are going to make polygons, with your
routine, or use it for gouraud interpolation, you
won't need more than one pixel per scanline, and
the DDA won't use more than 2-3 clock cycles per
pixel in any case. Eat that, Bresenham!

Here is a cute little table to display the above
equations in an easier way...:


Pixels drawn:                   db
20                             bb
                              b
                            bb
                           bd
                         bbd
15                      b d
                      bb d
                     b  d                'b' = b(t)
                   bb  d                 'd' = d(t)
                  b   d
10              bb   d
               b    d
             bb    d
            b     d
          bb     d
5        b      d
       bb      d
      b       d
    bb       d
1  b        d
0bbddddddddd
 ^    ^    ^    ^    ^    ^    ^    ^    ^   ^   ^
 0    25   50   75   100  125  150  175  200 225 250 clock ticks


BTW, once I tried to get rid of the DIV in the DDA routine.
What I came up with was am exact copy of Bresenham.
So old Bressy did know what fixedpoint was, I'd recon
that the computers at that time were so much slower
with DIV, that his routine was faster.

But NOT today!

BTW again, if anyone wonders how the DDA is done with 2 cc
per pixels, look here:

adc     edi,ebx
mov     [di],al

The top 16 bits of edi contains the decimals and ebx
contains the x-add. If you want to optimize it further,
I think it's possible to do like this:

adc	esi,ebx
mov	[di],al
adc	edi,ebx
mov	[si],al

where you have doubled ebx.

That's all, folks!

 // i




--
      _  _  _  _  _    ___  _  ___  ____
     < >| || || || | _|  _|< >|o  ||    |
     |_||_||_||____||___|  |_||___||_||_|
    Graphician, Phoenix Realtime Productions
      http://www.edu.isy.liu.se/~d94marka/

###
###

Subject: Re: Bresenham algorithm for an ellipse ?
From:  (Chris Lattner)
Date: 18 Jan 1996 23:40:36 GMT

: I am looking an algorithm for drawing an ellipse .
: The input shall be the midpoint and the two axes .

Here is one implementation in C of the algorithm...

Remark : Only one quarter of the ellipse is computated, the rest
         is set by symmetry.

         a  and  b  are the half-axes (I hope this is the right
         word for it) of the ellipse in  x- and y-direction.
         If you like a circle set  a=b=radius  .

--------------------------------- cut ---------------------------------
void symmetry(x,y)
int x,y;
{
 PUT_PIXEL(+x,+y);  // This would obviously be inlined!
 PUT_PIXEL(-x,+y);  // and offset by a constant amount
 PUT_PIXEL(-x,-y);
 PUT_PIXEL(+x,-y);
}

void bresenham_ellipse(a,b)
int a,b;
{
 int x,y,a2,b2, S, T;

 a2 = a*a;
 b2 = b*b;
 x = 0;
 y = b;
 S = a2*(1-2*b) + 2*b2;
 T = b2 - 2*a2*(2*b-1);
 symmetry(x,y);
 do
   {
    if (S<0)
       {
        S += 2*b2*(2*x+3);
        T += 4*b2*(x+1);
        x++;
       }
      else if (T<0)
          {
           S += 2*b2*(2*x+3) - 4*a2*(y-1);
           T += 4*b2*(x+1) - 2*a2*(2*y-3);
           x++;
           y--;
          }
         else
          {
           S -= 4*a2*(y-1);
           T -= 2*a2*(2*y-3);
           y--;
          }
    symmetry(x,y);
   }
 while (y>0);
}

Have fun!
Chris

_.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._
      Chris     | Home page: http://www.teleport.com/~sabre
     Lattner    | For all your PC programming needs!  Articles,
My Propaganda-> | reference, links, EVERYTHING!
^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^

###

Subject: Re: I need help in finding if a point is near a line
From:  (Kevin Stone)
Date: 16 Jan 1996 22:32:44 GMT

Lance Wentz () wrote:
: Jason Reeve wrote:
: >
: > My problem, 2D vector maths. I have 2 sprites A and B. I want to see
: >if another sprite C is inbetween A and B allowing for some tolerance
: > either side. Any help

    You have to do two tests... the first test needs to find if sprite
C is inbetween sprite A and B, and the second test needs to find the
distance that sprite C is from the line between sprites A and B and
compare that distance to your tollerance.

    The answer to the first test is surprisingly simple...

   A
    \             This is a diagram of the situation.  Sprites A and B
     \  C         form a line, and sprite C is somewhere in space.
      \           We need two vectors... A vector in the direction of line
       \          AC and a vector in the direction of the line BC.
        B
    By taking the Dot Product of vector AC and BC you will find if sprite
    C possibly lies inbetween A and B.  If the result of the Dot is less
    than 0 then sprite C is inbetween A and B (such as the situation in
    this diagram), if it's greater than 0 then sprite C is not inbetween
    A and B.

    The second test is easy as well...

    We need to find the distance that sprite C is to the line AB.  This
    can be done with a little trig...

    A       Ive rotated the situation alittle bit so it's easier to draw.
    |\      I've also added a point, "D".  Line DC is what we need to find.
    | \     We need to find the angle between lines AC and AB.  This is
    D--C    easily done with the Dot Product of those two vectors.
    | /     Once we have that angle, we can use the Cosine Law to
    |/      solve the triangle ACD, and with that, we can find the length
    B       of line DC... which is the distance that sprite C is from the
            line AB.


   I will call the angle between AC and AB, theta.

   Theta = ArcCosine((AB dot AC) / (|AB|*|AC|));  // By the Dot Poduct law

   |DC| = (|AC| * cos(Theta)) / cos(90)

   Now you can apply your tollerance to the length of DC and do what ever
   you need to do. :)

I sure hope this works.

   Here's a summary of the algorithm...

      Given two sprites A and B, find if sprite C lies in between A and
      B.  If it does, find the distance that C is from the line formed by
      A and B.
      The code might look something like this...

      if (Dot(AC, BC) < 0)
      {
          Theta = acos(Dot(AB, AC)/(Length(AB)*Length(AC));
          DistToLine = abs(Length(AC)*cos(Theta) / cos(90))
          if (DistToLine < Tollerance)
             SpriteC_InBetweenSpritesAB = true;
      }
      else
          SpriteC_InBetweenSpritesAB = false;

BAS


"Visual Arts & Communications" http://www.ee.pdx.edu/~igal/visocomm/ by Igal Koshevoy (???)

_The Computational Beauty of Nature: Computer Explorations of Fractals, Chaos, Complex Systems, and Adaptation_ book by Gary Flake has source code online at http://mitpress.mit.edu/books/FLAOH/cbnhtml/

Lifelike Computer Characters http://www.research.microsoft.com/research/ui/lcc/ Bruce Sterling's Closing Address on Artificial Life ???

daVinci http://www.informatik.uni-bremen.de/~davinci/ mirror http://www.tzi.de/~davinci/ is a X-Window visualization tool for drawing directed graphs automatically in high quality. Windows NT version available. Automatic graph layout with edge crossing- and bend minimization. Interactive fine tuning for a given layout. Interactive abstractions (collapsing subgraphs, hiding edges). Application programmers can use the daVinci API to draw graphs without having to deal with graph layout algorithms and computer graphics. organization trees, tree-like data structures, ... http://www.informatik.uni-bremen.de/~mfr/

the GGI Project http://synergy.caltech.edu/~ggi/ "GGI stands for "General Graphics Interface", and it is a project that aims to develop a reliable, stable and fast graphics system that works everywhere. We want to allow any program using GGI to run on any platform requiring at most a recompile. ... GGI development also involves a portable userspace library, 3D graphics, and anything else that is fun to hack :-)"

the _Fractal Report_ http://www.geocities.com/CapeCanaveral/Launchpad/5113/ lots of enthusiastic articles about making computer graphics with simple BASIC programs. BASIC and C source code included.

http://www.comlab.ox.ac.uk/archive/3d.html single image random dot stereo (SIRDS) and other 3-D images and software. A few pointers to things of more than 3 dimensions.

http://eddie.mit.edu/ftp/pub/three-d-zone/ some postscript utilities for various 3 D object manipulation.

togglethis http://www.togglethis.com/ ???

$79 CD Labeler package (die-cut labels, templates, centering application tool) http://www.neato.com/

http://www.gifoptimizer.com/ ???

GRAFICA Obscura http://www.sgi.com/grafica/ "Collected Computer Graphics Hacks" Curated by Paul Haeberli A couple of them are about paper folding ( origami ), with nary a computer in sight. fonts; image merging (projective warp panorama), Texture Mapping Applications, and a few other clever ideas.

http://www.scitechsoft.com/ ???


This page started 1997 Mar 29 by David Cary and has backlinks

known by AltaVista

known by Yahoo!

known by infoseek

Send comments, suggestions, errors, bug reports to

David Cary
d.cary+computer_graphics_tools@ieee.org.

Return to index // end http://david.carybros.com/html/computer_graphics_tools.html