where : ibrtses delphi

Delphi - mapping world and screen

disclaimer

the source code of this page may not appear correctly in certain browsers
due to special characters. Have a look at the source of this HTML page
with notepad instead

Mapping world and screen coordinate systems to each other is
done by scaling with respect to an offset.

be the world window be defined as:
  
 [xLow..xHigh,yLow..yHigh], the coordinates are of type float

be the screen window be defined as:

 [tlx..brx,tly..bry], the coordinates are of type integer

the following function do the conversion :

   function mapW2SxLin(xf:float):integer;
   begin
    result:=round(tlx+(xf-xlow)*(brx-tlx)/(xhigh-xlow));
   end;

   function mapW2SyLin(yf:float):integer;
   begin
    result:=round(bry-(yf-ylow)*(bry-tly)/(yhigh-ylow));
   end;

   function mapS2WxLin(xs:integer):float;
   begin
    result:=xlow+(xs-tlx)*(xhigh-xlow)/(brx-tlx);
   end;

   function mapS2WyLin(ys:integer):float;
   begin
    result:=yhigh-(ys-tly)*(yhigh-ylow)/(bry-tly);
   end;

Logarithmic axis may used to display signal amplitudes amongst
other things. For a logarithmic scale use :

   function mapW2SxLog(xf:float):integer;
   begin
    result:=round(tlx+(ln(xf/xlow)/ln(xhigh/xlow))*(brx-tlx));
   end;

   function mapW2SyLog(yf:float):integer;
   begin
    result:=round(bry-round((ln(yf/ylow)/ln(yhigh/ylow))*(bry-tly)));
   end;

   function mapS2WxLog(xs:integer):float;
   begin
    result:=xlow*exp(((xs-tlx)/(brx-tlx))*ln(xhigh/xlow));
   end;

   function mapS2WyLog(ys:integer):float;
   begin
    result:=yhigh/exp(((ys-tly)/(bry-tly)*ln(yhigh/ylow)));
   end;

Improvements




Feedback is welcome





sponsored links




Delphi
home

last updated: 24.july.99

Copyright (99,2000) Ing.Büro R.Tschaggelar