kill(all)$

load packages
=============

load(lrats)$

Computation : pixels coordinates to user coordinates ,version 1.0
peter.vlasschaert@gmail.com, 09/02/2019

1e)  linear relation between : pixel coordinates and user coordinates.
==========================================================

Reactangle : ABCD  = canvas 
=========================

point  A : origin (0,0)   
=======
point  B :   x- direction   A => B  (pixels)   :  x_pix
=======
point  D :   y-directiopn  A => D (pixels)    :  y_pix
=======
=> x_pix, y_pix  , pos integer.

linear : relation  :  px = a11*x+ a12
                                py = a21*y +a22
------------------------------------------------------------------------
px,py = pixels  ,  x,y = user coordinates
-------------------------------------------------------------------------

==========================================
pixel coordinates
===============
set windows   0,x_pix-1,y_pix-1,0      'Truebasic'
----------------------------------------------------------------------------
user coordinates
==============
set window  xmin,xmax,ymin,ymax     'Truebasic'
===========================================
see :  graph pixel : part 1  , 'draw a line', version 1.0

p1  : px=a11*x+a12;
p1a:py=a21*y+a22;

relation between : pixel coordinates ⇔ user coordinates
===============================================
constraint: to find a11,a12,a21,a22

p2: x = xmin;
p2a: px = 0;

p3: x= xmax;
p3a: px = x_pix;

p4: y =ymin;
p4a: py = y_pix;

p5: y= ymax;
p5a: py =0;

solve problem : four equations   to find : {a11,a12,a21,a22}
=============================================

p6a:subst([p2,p2a],p1);
p6b:subst([p3,p3a],p1);
p6c:subst([p4,p4a],p1a);
p6d:subst([p5,p5a],p1a);

p7:to_poly_solve([p6a,p6b,p6c,p6d], [a11,a12,a21,a22]);

p7a:part(p7,1,1);
p7b:part(p7,1,2);
p7c:part(p7,1,3);
p7d:part(p7,1,4);

general equations, between : pixel coordinates-user coordinates
===================================================
use : {p1,p1a}

p8:[p7a,p7b,p7c,p7d];
p8a:subst(p8,p1);
p8b:subst(p8,p1a);

How to draw :  x-axis   
================
from : xmin ≤ x ≤ xmax , y=0

p9a:pxa = subst([x=xmin],rhs(p8a));
p9b:pxb = subst([x=xmax],rhs(p8a)),ratsimp;
p9c:pxc = subst([y=0],rhs(p8b));

def :x-axis
=========

line : (pxa,pxc) to (pxb,pxc)

How to draw :  y-axis   
================
from : ymin ≤ y ≤ ymax , x=0

p10a:pxaa = subst([y=ymin],rhs(p8b)),ratsimp;
p10b:pxbb = subst([y=ymax],rhs(p8b));
p10c:pxcc = subst([x=0],rhs(p8a));

def :y-axis
=========

line : (pxcc,pxaa) to (pxcc,pxbb)

How to draw  : x  => F(x)
===================

Basic :
=====
for  x = xmin to xmax step value
     y = F(x) 
     px=(x_pix*xmin)/(xmin-xmax)-(x*x_pix)/(xmin-xmax)
     py=(y*y_pix)/(ymin-ymax)-(y_pix*ymax)/(ymin-ymax)
     plot px,py
next x
  

To draw function : F(x)
==================

1e) value : float 

2e) given :{x_pix,y_pix,xmin,xmax,ymin,ymax}

'======================================================='