Up \Display

{@abstract(TPlot2D and TPlotBox2D classes)
author: Nikolai Shokhirev)
created: June 06, 2002)
last modified: August 08, 2003)
ŠNikolai V. Shokhirev, 2002-2003  }

{ The unit for simple 2D graphics }
{                                                       }
{ Basic notations and expressions                       }
{                                                       }
{        0       LdW                iW-RdW    iW    iX  }
{                                                       }
{      0 +--------+--------------------+-------+-- YT   }
{        |                                     |        }
{        |        Y                            |        }
{        |        |                            |        }
{   TdH  +  Ymax  +--------------------+       +        }
{        |        |                    |       |        }
{        |        |                    |       |        }
{        |        |                    |       |        }
{        |        |                    |       |        }
{        |        |                    |       |        }
{        |        |                    |       |        }
{        |        |                    |       |        }
{ iH-BdH +  Ymin  +--------------------+-- X   +        }
{        |                                     |        }
{        |       Xmin                 Xmax     |        }
{        |                                     |        }
{   iH   +--------+--------------------+-------+ YB     }
{        |                                              }
{        |                                              }
{   iY                                                  }
{ TdH - Plot Top offset (pixels)                        }
{ BdH - Plot Bottom offset (pixels)                     }
{       Ymin    <=  Y <= Ymax                           }
{ iH > iH - BdH >= iY >= TdH >= 0                       }
{                                                       }
{ LdW - Plot Left offset (pixels)                       }
{ RdW - Plot Right offset (pixels)                      }
{      Xmin <=  X <= Xmax                               }
{ 0 <= rLdW <= iX <= rW-rRdW < rW                       }
{
(ix-LdW)/(iW-RdW-LdW)=(x-Xmin)/(Xmax-Xmin)
(iH-BdH-iy)/(iH-BdH-TdH)=(y-Ymin)/(Ymax-Ymin)

(ix-LdW)*(Xmax-Xmin)=(iW-RdW-LdW)*(x-Xmin)
(iH-BdH-iy)*(Ymax-Ymin)=(iH-BdH-TdH)*(y-Ymin)

ix-LdW = (iW-RdW-LdW)*(x-Xmin)/(Xmax-Xmin)
iH-BdH-iy = (iH-BdH-TdH)*(y-Ymin)/(Ymax-Ymin)

x-Xmin = (ix-LdW)*(Xmax-Xmin)/(iW-RdW-LdW)
y-Ymin = (iH-BdH-iy)*(Ymax-Ymin)/(iH-BdH-TdH)

ix = iW - RdW
Xmax = Xmin + (iW-RdW-LdW)*(Xmax-Xmin)/(iW-RdW-LdW)

iy = TdH
Ymax = Ymin + (iH-BdH-TdH)*(Ymax-Ymin)/(iH-BdH-TdH)

ix = 0
XL = Xmin - LdW*(Xmax-Xmin)/(iW-RdW-LdW)

ix = iW
XR = Xmin + (iW-LdW)*(Xmax-Xmin)/(iW-RdW-LdW)
   = Xmax - (iW-RdW-LdW)*(Xmax-Xmin)/(iW-RdW-LdW)
          + (iW-LdW)*(Xmax-Xmin)/(iW-RdW-LdW)
   = Xmax + RdW*(Xmax-Xmin)/(iW-RdW-LdW)

iy = 0
YT = Ymin + (iH-BdH)*(Ymax-Ymin)/(iH-BdH-TdH)
   = Ymax - (iH-BdH-TdH)*(Ymax-Ymin)/(iH-BdH-TdH)
          + (iH-BdH)*(Ymax-Ymin)/(iH-BdH-TdH)
   = Ymax + TdH*(Ymax-Ymin)/(iH-BdH-TdH)

iy = iH
YB = Ymin - BdH*(Ymax-Ymin)/(iH-BdH-TdH)
}
{                                                    }
{       0      LdW                 W-RdW   iW    iX  }
{                                                    }
{     0 +-------+--------------------+------+-- YT   }
{       |                                   |        }
{       |    YTitle                         |        }
{       |                                   |        }
{  TdH  +  5e-1 +--------------------+      +        }
{       |       |                    |      |        }
{       |       |                    |      |        }
{       |       |                    |      |        }
{       |  0e+0 +                    |      |        }
{       |       |                    |      |        }
{       |       |                    |      |        }
{       |       |                    |      |        }
{ H-BdH + -5e-1 +---------+----------+      +        }
{       |      1.1e1     1.2e2      1.3e3   |        }
{       |                                   |        }
{       |                         XTitle    |        }
{       |                                   |        }
{   iH  +-------+--------------------+------+ YB     }
{       |                                            }
{       |                                            }
{   iY                                               }
unit uGraph2D;

interface

uses
  uMatTypes, extctrls, graphics, classes, controls;

type

  TYofX = function(const x: TFloat): TFloat;

  TPlot2D = class
  private
  public
    constructor Create(Xmin, Xmax, Ymin, Ymax: TFloat);
    destructor Destroy; override;
    property Xmin: TFloat read GetXmin write SetXmin;
    property Xmax: TFloat read GetXmax write SetXmax;
    property Ymin: TFloat read GetYmin write SetYmin;
    property Ymax: TFloat read GetYmax write SetYmax;
    property Canvas: TCanvas read GetCanvas write SetCanvas;
    property Height: TInt read GetHeight write SetHeight;
    property Width: TInt read GetWidth write SetWidth;
    procedure MoveToF(x, y: TFloat);
    procedure LineToF(x, y: TFloat);
    procedure LineF(x1, y1, x2, y2: TFloat);
    procedure PlotFrame(XCaption, YCaption: boolean; NXTicks, NYTicks: TInt;
                        const XTitle, YTitle: string; XYRatio: TFloat = 1.0);
   end;

  TPlotBox2D = class(TPaintBox)
  private
  public
    constructor Create(aOwner: TComponent; aParent: TWinControl);
    destructor Destroy; override;
    { Xi2r(rLdW) = Xmin,  Xi2r(iW-rRdW) = Xmax}
    function Xi2r(iX: TInt): TFloat;
    { Yi2r(iH - BdH) = Ymin,  Yi2r(TdH) = Ymax}
    function Yi2r(iY: TInt): TFloat;
    procedure SetLimits(Xmin, Xmax, Ymin, Ymax: TFloat);
    procedure Circle(x, y: TFloat; r: TInt);
    procedure MoveToF(x, y: TFloat);
    procedure LineToF(x, y: TFloat);
    procedure LineF(x1, y1, x2, y2: TFloat);
    procedure PlotFrame;
    property Xmin: TFloat read GetXmin write SetXmin;
    property Xmax: TFloat read GetXmax write SetXmax;
    property Ymin: TFloat read GetYmin write SetYmin;
    property Ymax: TFloat read GetYmax write SetYmax;
    property BrushColor: TColor read GetBrushColor write SetBrushColor;
    property PenColor: TColor read GetPenColor write SetPenColor;
    property PenWidth: TInt read GetPenWidth write SetPenWidth;
    property XCaption: boolean read fXCaption write fXCaption;
    property YCaption: boolean read fYCaption write fYCaption;
    property NXTicks: TInt read fNXTicks write fNXTicks;
    property NYTicks: TInt read fNYTicks write fNYTicks;
    property XTitle: string read fXTitle write fXTitle;
    property YTitle: string read fYTitle write fYTitle;
    property XYRatio: TFloat read fXYRatio write fXYRatio;
    property FrameColor: TColor read fFrameColor write fFrameColor;
   end;
   
implementation

end;

end.

Up \Display