A Very Simple Approach for -D to -D appig Sadipa Dey (1 Ajith Abraham ( Sugata Sayal ( Sadipa Dey (1 Ashi Software Private Limited INFINITY Tower II 10 th Floor Plot No. - 4. Block GP Salt Lake Electroics Complex Sector V Kolkata 700091 Ajith Abraham ( IITA Professorship Program School of Computer Sciece Yosei Uiversity 14 Shicho-dog Sudaemoo-ku Seoul 10-749 Republic of Korea Email: ajith.abraham@ieee.org Sugata Sayal ( School of Techology & Computer Sciece Tata Istitute of Fudametal Research Homi Bhabha Road umbai - 400005 INDIA email: sayal@tifr.res.i
Abstract ay times we eed to plot -D fuctios e.g. i may scietific experimets. To plot the -D fuctios o -D scree it requires some kid of mappig. Though OpeGL DirectX etc -D rederig libraries have made this job very simple still these libraries come with may complex pre-operatios that are simply ot iteded also to itegrate these libraries with ay kid of system is ofte a tough trial. This article presets a very simple method of mappig from -D to -D that is free from ay complex pre-operatio also it will work with ay graphics system where we have some primitive -D graphics fuctio. Also we discuss the iverse trasform ad how to do basic computer graphics trasformatios usig our coordiate mappig system. 1. Itroductio We have a fuctio f :R R ad our itetio is to draw the fuctio i - D plae. The fuctio z = f(x y is a -variable fuctio ad each tuple (x y f(x y R. Let s say we wat to graphically plot f oto computer scree usig a primitive graphics library (like Turbo C graphics which supports oly the basic putpixel (to draw a pixel i - D scree -like - D rederig fuctio but o - D rederig; i.e. our graphics library s putpixel s domai is R ad it s ot R. Hece i order to draw the fuctio f usig our graphics library we must desig a coordiate coversio system that will provide us with a fuctio that will take as iput -tuples (x y f(x y ad produce as output a - tuple ( x y that ca be directly passed to our graphics library to plot it oto the scree but with - D look & feel. As we discussed it s essetial that we have a simple coordiate mappig system that maps R to R ad still gives us a hypothetical feelig of drawig - D fuctios. It s very easy to fid such a map i.e. a fuctio h that maps from R to R i.e. h :R R ad i this paper we try to fid such a simple map.. Proposed approach We have a pictorial represetatio (Figure 1 of our - D to - D mappig system: Figure 1. Basic odel of a simple - D to - D mappig system But how the fuctio f should look like after mappig ad plottig? Here we simulate the rd coordiate (amely Z i our - D x-y plae. We perform the logical to physical coordiate trasform ad everythig by the map fuctio h which will basically tur out to be a matrix. The basic mappig techique is show i figure- which we are shortly goig to explai. (0 0 Figure.The basic coordiate mappig (w h If we have our Origi O at (xo yo scree coordiate we have
x' = xo + y - x.si( θ = yo - z + x.cos( θ i.e. we have our -D to -D trasformatio matrix: (1 Followig surfaces (figure- ad figure-4 are draw i Turbo C++ versio.0 (BGI graphics usig the above simple -D to -D mappig: si( θ cos( θ = 1 0 ( Agai we have shiftig (chage of origi by the matrix O = [xo yo] so that we have followig O + PD = P where deotes matrix multiplicatio ad + deotes matrix additio the -tuple PD = [x y z] the -tuple P = [x y] i.e. siθ cosθ [ xo yo] + [ x y z]. 1 0 = [ x' ] ( matrix matrix matrix matrix Figure. Sie fuctio draw i TurboC++ Ver.0 (BGI Graphics usig -D to -D mappig By default we keep the agle betwee X axis & Z axis = θ = π / 4 that oe ca chage if required but with the followig iequality strictly satisfied: 0 < θ < π /. Oe ca optioally use a compressio factor to cotrol the dimesio alog Z-axis by a compressio factor ρ z ad slightly modifyig the equatios: x' = xo + y - x.si( θ = yo - ρ z. z + x.cos( θ (4 Obviously 0.0 < ρ z < 1.0 By default we take ρ z =1. 0. Sample Output Surfaces draw usig the above mappig: Figure 4. Syc fuctio draw i TurboC++ Ver.0 (BGI Graphics usig the - D to - D mappig
4. Iverse Trasformatio - Obtaiig origial -D coordiate from the trasformed -D coordiate Here our trasformatio fuctio (matrix is: x' = xo + y - x.si( θ = yo - z + x.cos( θ (5 As we ca see it is impossible to re-covert ad obtai the origial set of coordiates amely (x y z because we have ukows ad equatios. So i order to be able to get the origial coordiates back we at least eed to store tuples as result of the trasformatio for istace (x y z (x y z the z-coordiate beig stored oly to get the iverse trasform of the form ( x y z (x y z ad the ( x y pair is used to plot the poit. So i order to get the iverse trasformatio we eed to solve the equatios for x y sice we already kow z we have -equatios ad ukow variables: y x.si( θ = x' xo x.cos( θ = - yo + z Solvig the above equatios we get x = ( - yo y = x' xo + ( + z.sec( θ - yo + z. ta( θ (6 (7 Put it i aother way our trasformatio matrix is a matrix si( θ cos( θ = 1 0 (8 Sice a o-square matrix o questio of existece of its iverse. So i order to be able to get the iverse trasform as well we eed a ivertible square matrix e.g. si( θ cos( θ 0 = 1 0 0 1 (9 with si( θ cos( θ 0 Det( det 1 0 0 X = 1 (10 si( θ cos( θ = 1. = cos( θ 1 0 Now 0 < θ < π / hece cos( θ 0 hece Det( 0 ad the iverse exists. si( θ cos( θ 0 [ xo yo 0] + [ x y z]. 1 0 0 = [ x' z] 1 1 matrix matrix matrix matrix (11 But we have Iv( Det( = ( 0 Adj( = Det( ad 0 cos( θ 0 Adj ( = si( θ 0 si( θ cos( θ (1 Hece 0 1 0 Iv ( = = sec( θ ta( θ 0 sec( θ ta( θ 1 Here cos( θ 0 (1 So the iverse trasform is:
si( θ 0 cos( θ 0 1 [ x y z]. 1 0 0 = [ x' z] [ xo yo 0] [ x y z] = [ x' xo yo z]. 0 sec( θ sec( θ 1 ta( θ ta( θ 0 0 1 [( - yo+ z.sec( θ x ' + (- yo+ z.ta( θ z] = xo (14 This exactly matches with our previous derivatio. 5. Rotatio ad affie trasformatios A poit i -D after beig mapped to -D scree followig the above mappig procedure may be required to be trasformed usig stadard computer graphics trasformatios (traslatio rotatio about a axis etc. But i order to udergo such a graphics trasformatio ad to show the poit back to the scree after the trasformatio it eeds to go through the followig steps i our previously-described coordiate mappig system: First obtai the iverse coordiate trasformatio to obtai the origial - D coordiates from the mapped - D coordiates ultiply the - D coordiate matrix by proper graphics trasformatio matrix i order to achieve graphical trasformatio. Use the same - D to - D map agai to plot the poit oto the scree. These steps ca be mathematically represeted as: P D = P ( P ' = P T D D D P ' = P ' (15 Or by a sigle-lie expressio P ' = ((P ( T (16 Here as before deotes matrix multiplicatio ad T deotes the traditioal graphics trasformatio matrix. But sice we kow the fact that matrix multiplicatio is associative we have P P ' = ((P where = P = P ' = P ( ' T T T ' = T (17 So usig this simple techique we ca escape the successive matrix multiplicatios everytime a poit o scree eeds to trasformed istead what we ca simply do is pre-compute ' = T. (18 This matrix ' is eeded to be computed oce for a give graphics trasformatio (e.g. rotatio about a axis ad applied to all poits o the scree so that usig a sigle matrix multiplicatio thereafter ay poit o the scree ca udergo graphics trasformatio by P ' = P ' where P represets the poit mapped before trasformatio T ad P is the poit re-mapped after the trasformatio as obvious. Hece usig the above tricks we are able to make the trasformatio more computatioally efficiet.
oreover if a trasformatio is eeded to be applied simultaeously we ca use the property (T = ( T where (T deotes ( times is a positive iteger simultaeous matrix multiplicatio of T. Let s say we have already udergoe a T trasformatio so that we have already computed = T ad let s say that we also have frequet simultaeous (T trasformatio. I order to udergo a (T trasformatio we first eed to compute the matrix (T the we eed to compute our ew matrix = (T so we eed total + matrix multiplicatios everytime we wat a (T trasform for each. But if we have computed T iitially here the trick is that we ca reuse this it to compute our ew matrix i the followig maer: = (T (19 = ( T = ( Here we eed ot compute (T ad every-time istead we eed to compute ( oly (that ca be icremetal multiplicatio to icrease efficiecy. 6. Coclusios This article preseted a very simple method of mappig from - D to - D that is free from ay complex pre-operatio. The proposed techique works with ay graphics system where we have some primitive - D graphics fuctio. We also discussed the iverse trasform ad how to do basic computer graphics trasformatios usig our coordiate mappig system. 7. Refereces [1] Rogers David F Procedural elemets for computer Graphics d editio cgraw-hill 1998 pp. 65-87. [] Rogers David F. Adams J. Ala athematical Elemets for Computer Graphics d editio cgraw-hill 1990 pp. 61-06. [] Ng C.. Bustard D. W. A New Real Time Geometric Trasformatio atrix ad its Efficiet VLSI Implemetatio Computer Graphics Forum December 1994 Vol. 1 pp. 84-85. [4] Shreier Dave Woo aso Neider Jackie Davis Tom OpeGL Programmig Guide Versio 1.4 Fourth Editio Pearso Educatio 004 pp. 10058. [5] Turkowski Ke Fixed-Poit Trigoometry with CORDIC Iteratios Graphics Gems I Academic Press 1990 pp. 494-497. [6] Turkowski Ke The Use of Coordiate Frames i Computer Graphics Graphics Gems I Academic Press 1990 pp. 5-5. [7] Joy Ke O-Lie Computer Graphics Notes Computer Sciece Departmet Uiversity of Califoria Davis 1999. [8] Ducker ike atrix ad Vector aipulatio for Computer Graphics November 9 000. [9] Howlad Joh E. Computer Graphics Departmet of Computer Sciece Triity Uiversity October 4 005. [10] Keith Stepha R. A Trasformatio Structure for Aimated -D Computer Graphics AC SIGGRAPH Computer Graphics Vol. 15 Issue 1 April 1981 pp 7-91.