Delphi Graphics: Algorithms 
A. General Graphics  B. Color  C. Image Processing  D. Mathematics/Geometry 
in  look for 
Delphi
Graphics 
2D/3D  GraphicsMathPrimitives. 2D/3D Clipping, 3Dto2D Projections. See 2D/3D vector graphics examples on efg's Graphics projects page. 

Angle  USES
Math; // ArcTan2
// Given points(iText,jText) and (iTarget,jTarget). The angle
between Clock Angles 

Arcs 
The TCanvas.Arc method is is not that easy to use for some applications. The DrawArcs demo shows how to define a bounding rectangle and then draw the specified type of arc between opposite corners of the rectangle. TYPE BoundRect := Rect(xMin,yMin, xMax,yMax); 

Area 
efg's Polygon Area and Centroid Lab Report
Paul Nicholls' UseNet Post
about how to compute polygon area using 3D points TriangleArea and TriangleHeight functions in William Egge's EMath unit 

Aspect Ratio  efg's Aspect Ratio Lab Report  
Axes  For an explanation of the following diagram,
see the Discussion
section of the Basketball Lab
Report.
See efg's MapWorldToPixel unit for a quick way to map (x,y) to (i,j). Dave Shapiro's UseNet Post explaining "Why is 'y' upside down?" (or how to make the yaxis increase from bottomtotop instead of toptobottom) See GraphicsMath (below) for Pantograph objects that perform this mapping for 2D/3D vectors, along with projections and clipping.
"Windows 95/98 uses a 16bit world coordinate system and restricts x and y coordinates for text and graphics to the range ±32K. Windows NT/Windows 2000 uses a 32bit world coordinate system and allows coordinates in the range ±2 gigabytes (GB). If you pass full 32bit coordinates to text and graphics functions in Windows 95/98, the system truncates the upper 16 bits of the coordinates before carrying out the requested operation." "Because Windows 95/98 uses a 16bit coordinate system, the sum of the coordinates of the bounding rectangle specified by the Arc, Chord, Pie, Ellipse, and RoundRect functions cannot exceed 32K. In addition, the sum of the nLeftRect and nRightRect parameters or the nTopRect and nBottomRect parameters cannot exceed 32K."" [Of course Microsoft broke the link with this information so the original MSDN reference in no longer available.] 

Bézier Curve  Boris Novgorodov's UseNet
Post with PolyBezier example
JeanYves Queinec's Bézier project Béziers and Paths by Clinton R. Johnson Alexander Weidauer's UseNet Post
showing a "function to draw a Bézier curve starting from a
variable Drawing
Curves The "Bezier Draw" is a sample Delphi program to demonstrate the
use of "Bezier" unit. See PolyBezier API call 

Butterfly  
Charts  See Charts and Graphs on efg's Delphi Graphics Components and Programs page  
Circles  How to determine the circle through three given
points: efg's UseNet
Post1 and Post2
Division of Semicircle into 2^{N} Intervals Using
HalfAngle Formula and Rotation Formula See "Circle Approximation" as part of Polygon Area and Centroid Lab Report efg's UseNet Post about computing great circle distances 

Coordinate Systems  Tomes Graphical, pp. 1319  
Contours & Isosurfaces  http://huizen.dto.tudelft.nl/deBruijn/programs/suna55.htm
MUMIL  a cursor based contouring routine 

Cubic Curve  Lorc CRC's UseNet Post with DrawCubicCurve example  
Curves and Surfaces  NonDelphi site (in French): COURBES ET SURFACES MATHEMATIQUES http://perso.wanadoo.fr/roger.assouly 

Distance  Distance from point P1(x1, y1) to P2(x2, y2): SQRT( SQR(x1x2) + SQR(y1y2) ), or using a function from the math unit: Hypot(x1x2, y1y2). Distance from point P1(x1, y1) to Line, a*x + b*y + c = 0 DistPoint2Line and DistPoint2LineSegment functions in William Egge's EMath unit 

Elllipse, Rotated 


Ellipsoid  efg's UseNet Post with comments about how to draw an ellipsoid as a series of elliptical "slices"  
FloatingPoint Math  NonDelphi: "FloatingPoint for RealTime 3D," Chapter 63, Michael Abrash's Graphics Programming Black Book (out of print)  
Fractals  efg's Fractals and Chaos page Using a background thread to compute and display a Mandelbrot set using HSVcolor scheme, Delphi in a Nutshell, pp. 148151 Borland's Fractal Generator Contest Chapter 6, "3D Fractal Landscapes" in Kick Ass Delphi
Programming (out of print) 

Geometric Figure  Line Art on a TImage. This example draws lines on a
TImage resulting in this geometric figure. www.ecnet.net/users/gsmpati/delphi 

Geometry 
Geometry Library, Geometry.ZIP. This unit contains
types, functions and procedures for quaternion, vector and matrix arithmetics. It is
specifically designed for geometric calculations within R3 ("affine" vector
space) and R4 (homogeneous vector space). 

Graphics Math  efg's GraphicsMathLibrary
unit for Matrix/Vector Operations for 2D/3D Graphics using Homogeneous
Coordinates. Includes conversion between coordinate systems (Cartesian,
polar, spherical), matrix transforms (translation, rotation, scaling), and
a ViewTransformMatrix routine to compute how world coordinates
should be transformed for plotting from a given camera/eye location.
efg's GraphicsPrimitivesLibrary unit (uses GraphicsMathLibrary unit) defines a TPantoGraph class. A TPantoGraph object maps 2D/3D "World Coordinates" to a Delphi "Canvas". These World Coordinates are DOUBLE values that are defined using regular mathematical conventions. This means that instead of having increasing "Y" values as you go down a canvas, "Y" increases as you go up using the computer "pantograph". Includes clipping and various projection options. Suggestion by CC.Campbell for using TextOut with TPantograph 

Graphs  See Charts and Graphs on efg's Delphi Graphics Components and Programs page  
Hex Grid  John McDonnell's UseNet Post about drawing a hex grid  
Homogeneous Coordinates: Scaling, Rotation, Translation  [Foley96, pp.
204209] efg's TPantograph in Football, Sphere In Cube, or other Lab Reports 

Lines, Intersecting  http://www.delphiforfun.org/Programs/Math_Topics/intersecting_lines.htm  
Maps, Cartography  See Maps on Delphi Graphics Algorithms page  
Mathematics for Computer Graphics  [Foley96, Appendix, pp. 10831112]  
Matrix Transformations  GraphicsMathLibrary. 2D/3D matrices for translation, scaling,
rotation of homogeneous coordinates.ViewTransformMatrix. Part of any of the 2D/3D vector
graphics examples on efg's Graphics page. Matrices (and 3D graphics) www.geocities.com/SiliconValley/2151/matrices.html (NonDelphi) 

Moiré Patterns  efg's Daisy Lab Report  
Numeric Data to Bitmap 
How to create a Bitmap from numeric data? (D5)
Read TXT file into dynamically allocated matrix and show matrix as either gray scale or "rainbow" values: 10 8 (A "LargeMatrix" program is included to create large test matrices. A 1200by900 matrix will take about 5 minutes on a 650 MHz Pentium III.) 

Perimeter  efg's Email to Engineering Student at kmutt about how to computer perimeter of an object  
Perlin Noise  Michael Hansen's Perlin Noise project 

Pi  efg's Lab Report: Estimate value of pi using Buffon's "needles"  
Point in Polygon  Mat Ballard's UseNet
Post with PointInPolygonTest function
adub's UseNet Post with PtInPolygon using PtInRegion WinAPI call PointAndPolygon unit with PointInPolygon function by Philippe De Boe and Thérèse Hanquet Paul Nicholls' UseNet Post with pointinpolygon routine John Hutchings' UseNet Post with PointInPolygonTest function // InSide function by Andreas Filsinger Also see PtInRegion on Graphical Win32 API page 

Point in Triangle  Dave Eberly's UseNet Post:
Let the points be
(x0,y0,z0), (x1,y1,z1), (x2,y2,z2). Given (x,y), solve for s and t in (x,y) =
(x0,y0)+s*(x1x0,y1y0)+t*(x2x0,y2y0). The point is inside the triangle if s >=
0, t >= 0, and s+t <= 1. Then choose z = (1st)*z0+s*z1+t*z2. efg's Maxwell Triangle Lab Report 

Point on Line  Schoeneck Howell's UseNet
Post with pointonline function
efg's Line Stretch Lab Report with NearLine function 

Points, Angles  Calculating a point using angles and distance (FAQ 2915D) Calculating an angle from two points (and the origin) (FAQ 1917D) Finding distance between two points (FAQ 2928D) 

Polygons  NonDelphi: Michael Abrash's Graphics Programming Black Book, Chapter 39, "Fast Convex Polygons"  
Projections  D3toD2 and D2toD3 functions in William Egge's EMath unit  
Rectangles  Rectangles: A Closer Look at the TRect Windows Data Type. (CopyRect, InflateRect, IntersectRect, IsRectEmpty, OffsetREct, Rect, SetRect, SetRectEmpty, SubtractRect, UnionRect, ScreenToClient, ClientToScreen, pRect, ClipCursor), Delphi Informant, Aug. 1999.  
Splines  Splines by Charles Hacker www.gu.edu.au/school/eng/mmt/splines.zip BSplines.ZIP by Martijn an Engeland. Component for handling and displaying BSplines. Delphi Super Page: http://delphi.icm.edu.pl/ftp/d10free/bsplines.zip [Foley96, pp. 10131018] 

Surfaces  Surface Plot Collection. Components that know how to
plot surfaces given by formulas. Contains a component for (plain cartesian) graphs and one
for parametric surfaces www.xydot.com/delphi/math.htm#TD3Plot 

TMathImage  A TGraphicControl descendant that allows drawing in world
coordinates. Both 2D and 3D graphs are supported. Surfaces can be drawn filled with
hidden invisible parts and www.xydot.com/delphi/math.htm#MathImage60 

Spiral Transform  The "Twirl" program is based on the spiral transform from Beyond Photography: The Digital Darkroom (the book is online) by Gerard J. Holzmann, PrenticeHall, 1988, pp. 4445. The book gives the formula for transforming a picture of Ken Thompson (one of the originators of UNIX): new[radius, angle] = ken[radius, angle + radius/3] Twist.ZIP (D3D5 complete project with source code  BMPs not included) 

Transformation, Affine and Projective  Example code by Lazikas o Pontios for Intergraph Irasc files.  
Vector Graphics  Simple Vector Library http://sourceforge.net/projects/svl 
Note:
Foley96
(referenced above in several places) is not a Delphi book,
but is an excellent source for computer graphics algorithms.
Links Verified 11 Feb 2003
Updated 26 Feb 2005
since 6 Feb 2000