May be the following examples are useful, for those who have to change the coordinate system.
You need a drawing area and a command button to get the example going.
You can change the values of xmin, xmax, ymin and ymax, to fit your wishes.
Example 1 coordinate system
PUBLIC SUB Button1_Click() DIM dymax AS Integer ' maximal value of y = Height, which is drawn DIM dymin AS Integer ' minimal value of y, which is drawn ( = 0 ) DIM ymax AS Integer DIM ymin AS Integer DIM y AS Float DIM dy AS Float DIM dyi AS Integer DIM dxmax AS Integer ' maximal value of x = Width, which is drawn DIM dxmin AS Integer ' minimal value of x, which is drawn ( mostly dxmin = 0 ) DIM xmax AS Integer DIM xmin AS Integer DIM x AS Float DIM dx AS Float DIM dxi AS Integer dymax = DrawingArea1.Height dymin = 0 ymax = 4 ymin = -1 dxmax = DrawingArea1.Width dxmin = 0 xmax = 12 xmin = -1 'x-Axis is drawn FOR x = xmin TO xmax STEP 0.005 y = 0 ' Formula 'Relation of a length / maximallength is equal in both systems '(dy - dymin) / (dymax - dymin) = (y - ymin) / (ymax - ymin ) 'dy - dymin = (y - ymin) / (ymax - ymin ) * (dymax - dymin) dy = CFloat(y - ymin) / (ymax - ymin ) * (dymax - dymin) + dymin ' Formula for x '(dx - dxmin) / (dxmax - dxmin) = (x - xmin) / (xmax - xmin ) 'dx - dxmin = (x - xmin) / (xmax - xmin ) * (dxmax - dxmin) dx = CFloat(x - xmin) / (xmax - xmin ) * (dxmax - dxmin) + dxmin 'PRINT x,y,dx,dy dyi = Fix(dy) dxi = Fix(dx) Draw.Begin(DrawingArea1) Draw.Point(dxi,DrawingArea1.Height- dyi) Draw.End NEXT 'y - Axis is drawn FOR y = ymin TO ymax STEP 0.005 x = 0 dy = CFloat(y - ymin) / (ymax - ymin ) * (dymax - dymin) + dymin dx = CFloat(x - xmin) / (xmax - xmin ) * (dxmax - dxmin) + dxmin 'PRINT x,y,dx,dy dyi = Fix(dy) dxi = Fix(dx) Draw.Begin(DrawingArea1) Draw.Point(dxi,DrawingArea1.Height- dyi) Draw.End NEXT END
Example 2 y = 1 / x
Take the code from example 1. Get another Command button and put the following code to it. Be careful because when x = 0 then 1 / x will not work.
PUBLIC SUB Button2_Click() DIM dymax AS Integer DIM dymin AS Integer DIM ymax AS Integer DIM ymin AS Integer DIM y AS Float DIM dy AS Float DIM dyi AS Integer DIM dxmax AS Integer DIM dxmin AS Integer DIM xmax AS Integer DIM xmin AS Integer DIM x AS Float DIM dx AS Float DIM dxi AS Integer dymax = DrawingArea1.Height dymin = 0 ymax = 4 ymin = -1 dxmax = DrawingArea1.Width dxmin = 0 xmax = 12 xmin = -1 ' y = 1/x is drawn FOR x = 0.01 TO xmax STEP 0.005 y = CFloat(1) / x dy = CFloat(y - ymin) / (ymax - ymin ) * (dymax - dymin) + dymin dx = CFloat(x - xmin) / (xmax - xmin ) * (dxmax - dxmin) + dxmin dyi = Fix(dy) dxi = Fix(dx) Draw.Begin(DrawingArea1) Draw.Point(dxi,DrawingArea1.Height- dyi) Draw.End NEXT END
-- ReinerHoffmann - 18 Jan 2004