%!PS % Exactly fitting data points to a power curve % ============================================ % by Don Lancaster % Copyright c 2002 by Don Lancaster & Synergetics, Box 809, Thatcher, AZ, 85552 % (928) 428-4073 Email: don@tinaja.com Website: http://www.tinaja.com % Consulting services available http://www.tinaja.com/info01.html % Linking welcome. Reposting expressly forbidden. % All commercial rights and all electronic media rights ~fully~ reserved. % Linking usually welcome. Reposting expressly forbidden. Version 1.1 % A math tutorial on using power series to match data points. % Expands upon http://www.tinaja.com/psutils/curveft3.psl % IMPORTANT NOTE: Don Lancaster's file gonzo.ps is required for this program. % After obvious location mods, uncomment ONE of the following two lines: (C:\\windows\\desktop\\gonzo\\gonzo.ps) run % use internal gonzo % (A:\\gonzo.ps) run % use external gonzo % NOTE THAT ALL PS FILENAME STRINGS !!!DEMAND!!! DOUBLE REVERSE SLASHES. % GONZO20A Guru Gonzo PostScript power tools (Interim release) % Includes gonzo justification and layout utilities. % Copyright c 1990, 1996, 2001 by Don Lancaster and Synergetics, Box 809, % Thatcher Arizona, 5552 (928) 428-4073 don@tinaja.com support % via http://www.tinaja.com All commercial rights and all electronic % media rights **FULLY** reserved. Reposting is expressly forbidden. %%%%%%%%%%% links menu directory %%%%%%%%%%%% % This code locks pdfmark commands out of a PostScript printer. /pdfmark where {pop}{userdict /pdfmark /cleartomark load put} ifelse % /surl "start url" marks the beginning of a text sequence to be urled. % It also paints the text blue... /surl {mark /blue cvx 0.33 /setgray cvx % change text to blue /currentpoint cvx % remember box start /urly /exch cvx /store cvx /urlx /exch cvx /store cvx ] cvx % complete deferred command printlist exch 3 index exch put % stuff into gonzo printlist exch 1 add exch % increment gonzo list count } def % /eurl "end url" unmarks the end of a text sequence and sets up % the pdfmark needed to define the Acrobat web link. /eurl {mark % start deferred proc exch % position url string % /black cvx 0 /setgray cvx % turn blue marker off % maintextcolor /setrgbcolor cvx % reset to main text color??? /aqua cvx /black cvx /makeurl cvx % defer call of url builder ] cvx % complete deferred proc printlist exch 3 index exch % stuff into gonzo printlist put exch 1 add exch % increment gonzo list count } def % /makeurl generates the pdfmark, receiving a {(urlstring) makeurl}. % Note that it is not called until formatted printlist time... /urlover 0.2 def % fraction of hot area over bounds /makeurl { /cururlname exch store % save the url string mark % start pdfmark currentfont /ScaleMatrix get 3 get /fsize exch store % guess height /Rect [ urlx fsize urlover mul sub % set box left x urly fsize urlover mul sub % set box left y currentpoint exch fsize urlover mul add exch fsize add ] /Border [ 0 0 0] % [0 0 0 ] = none; [0 0 2] = debug /Color [ .7 0 0 ] /Action <> /Subtype /Link /ANN % annotation type pdfmark % call pdf operators } def % /makeurlx generates the box specific pdfmark, receiving % a {(urlstring) makeurl}. % Note that it is not called until formatted printlist time... /makeurlx { /cururlnamex exch store % save the url string mark % start pdfmark /Rect [ xpos % set box left x ypos 0.9 sub % set box left y xpos 2.8 add % box right x ypos 0.9 sub 2.8 add % box right y ] /Border [ 0 0 0] % [0 0 0 ] = none; [0 0 2] = debug /Color [ .7 0 0 ] /Action <> /Subtype /Link /ANN % annotation type pdfmark % call pdf operators } def /maintextcolor {0 0 0 } def % text link specific data -- use dictionary instead below { /cubic01 {(http://www.tinaja.com/cubic01.asp) eurl} def /hack62 {(http://www.tinaja.com/glib/hack62.pdf) eurl} def /increment {(http://www.tinaja.com/text/bezgen3.html) eurl} def /interpolate {(http://members.bellatlantic.net/~vze2vrva/design.html) eurl } def /bezmath {(http://www.tinaja.com/text/bezmath.html) eurl } def /table {(http://www.tinaja.com/psutils/imtable.psl) eurl } def } pop % dictionary method << %zzzzz %%%% unused links have been commented for gg9a simplicity /muse106 (http://www.tinaja.com/glib/muse106.pdf) /muse142 (http://www.tinaja.com/glib/muse142.pdf) /math01 (http://www.tinaja.com/math01.asp) /cubic01 (http://www.tinaja.com/cubic01.asp) /bez4pts (http://www.tinaja.com/glib/bez4pts.pdf) /muse145 (http://www.tinaja.com/glib/muse145.pdf) /muse148 (http://www.tinaja.com/glib/muse148.pdf) /curveft3 (http://www.tinaja.com/psutils/curveft3.psl) /fuzzybez (http://www.tinaja.com/glib/fuzzybez.pdf) /bmprpt01 (http://www.tinaja.com/psutils/bmprpt01.psl) /nowhit01 (http://www.tinaja.com/psutils/nowhit01.psl) /blender (http://www.tinaja.com/psutils/blender.psl) /speedup2 (http://www.tinaja.com/glib/speedup2.pdf) /histog01 (http://www.tinaja.com/psutils/histog01.psl) /imgviewer32 (http://www.arcatapet.net/imgv32.cfm) /basis (http://www.tinaja.com/glib/basis.pdf) /expbmp (http://www.tinaja.com/glib/expbmp.pdf) /dodbur01 (http://www.tinaja.com/psutils/dodbur01.psl) /dodgebur (http://www.tinaja.com/glib/dodgebur.pdf) /magfill1 (http://www.tinaja.com/psutils/magfill1.psl) /swingt01 (http://www.tinaja.com/psutils/swingt01.psl) /before01 (http://www.tinaja.com/images/bargs/marcon01.jpg) /during01 (http://www.tinaja.com/images/bargs/marcon01.bmp) /after01 (http://www.tinaja.com/images/bargs/marconz1.jpg) /repobmp (http://www.tinaja.com/glib/repobmp.pdf) /basis01 (http://www.tinaja.com/glib/basis.pdf) /arcata (http://www.arcatapet.net/imgv32.cfm) /comparebmp (http://www.designer-info.com/Writing/bmp_tiff_jpeg_gif.htm) /imagimag (http://www.tinaja.com/glib/imagimag.pdf) /myebays (http://www.tinaja.com/glib/myebays.pdf) /stepprep (http://www.tinaja.com/glib/stepprep.pdf) /aafont01 (http://www.tinaja.com/aafont01.asp) /here1 (http://village.infoweb.ne.jp/~fwhw1257/study/bmpform.htm) /here2 (http://www.daubnet.com/formats/BMP.html) /bittype (http://www.tinaja.com/psutils/pdf2bmp.psl) /photocombine (http://www.tinaja.com/psutils/blender.psl) /psl (http://www.tinaja.com/psutils/) % dummy temp /psl1 (http://www.tinaja.com/psutils/pdf2bmp.psl) /psl2 (http://www.tinaja.com/psutils/acatdata.psl) /psl3 (http://www.tinaja.com/psutils/catwords.psl) /psl4 (http://www.tinaja.com/psutils/graburls.psl) /psl5 (http://www.tinaja.com/psutils/blender.psl) /psl6 (http://www.tinaja.com/psutils/catools1.psl) /psl7 (http://www.tinaja.com/psutils/strconv.html) /psl8 (http://www.tinaja.com/psutils/bodcat.psl) /psl9 (http://www.tinaja.com/psutils/flatvue1.psl) /psl10 (http://www.tinaja.com/psutils/fern2img.psl) /psl11 (http://www.tinaja.com/psutils/flutools.psl) /psl12 (http://www.tinaja.com/psutils/mscal156q.psl) /psl13 (http://www.tinaja.com/psutils/weblogu2.psl) /psl14 (http://www.tinaja.com/psutils/pfa2pfb.psl) /psl15 (http://www.tinaja.com/psutils/pfb2pfa.psl) /psl16 (http://www.tinaja.com/glib/psdisk03.psl) /psl17 (http://www.tinaja.com/psutils/disktool.psl) /psl18 (http://www.tinaja.com/glib/psinscrt.psl) /psl19 (http://www.tinaja.com/glib/pssearch.psl) /psl20 (http://www.tinaja.com/text/refsum1.html) /psl21 (http://www.tinaja.com/text/reflog1.html) /psl22 (http://www.tinaja.com/psutils/reflog1.psl) /psl23 (http://www.tinaja.com/psutils/refsum1.psl) /psl24 (http://www.tinaja.com/psutils/searepl.psl) /psl25 (http://www.tinaja.com/psutils/weberru2.psl) /psl26 (http://www.tinaja.com/psutils/grabsrch.psl) /psl27 (http://www.tinaja.com/psutils/grabrefs.psl) /magsn01 (http://www.tinaja.com/magsn01.asp) /gonzoutils (http://www.tinaja.com/post01.asp#gonzo) /disktool (http://www.tinaja.com/psutils/disktool.ps) /elesimp (http://www.tinaja.com/glib/elesimp.pdf) /tn5603 (http://partners.adobe.com/asn/developer/pdfs/tn/TN5603.Filters.pdf) /fern2img (http://www.tinaja.com/psutils/fern2img.psl) /fern (http://www.tinaja.com/psutils/fern2img.pdf) /oldfern (http://www.tinaja.com/psutils/fernx1.pdf) /acrosdk (http://partners.adobe.com/asn/developer/acrosdk/main.html) /refman2 (http://partners.adobe.com/asn/developer/pdfs/tn/psrefman.pdf) /refman3 (http://partners.adobe.com/asn/developer/pdfs/tn/PLRM.pdf) /s3011 (http://partners.adobe.com/asn/developer/pdfs/tn/PS3010and3011.Supplement.pdf) /s2011 (http://ftp.ktug.or.kr/obsolete/info/adobe/devtechnotes/pdffiles/ps2011.supplement.pdf) /s2012 (http://ftp.ktug.or.kr/obsolete/info/adobe/devtechnotes/pdffiles/ps2012.supplement.pdf) /s2013 (http://ftp.ktug.or.kr/obsolete/info/adobe/devtechnotes/pdffiles/ps2013.supplement.pdf) /s2014 (http://ftp.ktug.or.kr/obsolete/info/adobe/devtechnotes/pdffiles/ps2014.supplement.pdf) /s2015 (http://ftp.ktug.or.kr/obsolete/info/adobe/devtechnotes/pdffiles/ps2015.supplement.pdf) /s2016 (http://ftp.ktug.or.kr/obsolete/info/adobe/devtechnotes/pdffiles/ps2016.supplement.pdf) /ghost (http://www.cs.wisc.edu/~ghost/) /distlang (http://www.tinaja.com/psutils/distlang.html) /adobepst (http://partners.adobe.com/asn/developer/technotes/) /maildon (mailto:don@tinaja.com) /tinaja (http://www.tinaja.com) /adobe (http://www.adobe.com) /adobesdk (http://partners.adobe.com/asn/developer/acrosdk/main.html) /pstrans (http://www.tinaja.com/glib/pstrans.pdf) /borland (http://www.borland.com/products/downloads/download_cbuilder.html) /ebay (http://cgi6.ebay.com/ws/eBayISAPI.dll?ViewSellersOtherItems&userid=abeja&completed=0&sort=2&since=-1&include=0&page=1&rows=100) /searepl (http://www.tinaja.com/psutils/searepl.psl) /aasdk (http://www.tinaja.com/plugins/AboutAcrobatSDK.api) /uncomp (http://www.tinaja.com/plugins/UncompressPDF.api) /addimage (http://www.tinaja.com/plugins/AddImage.api) /samplejpg (http://www.tinaja.com/plugins/sample.jpg) /transparency (http://www.tinaja.com/plugins/Transparency.api) /threerects (http://www.tinaja.com/plugins/threerects.pdf) /watermark (http://www.tinaja.com/plugins/Watermark.api) /verifyurls (http://www.tinaja.com/plugins/VerifyURLS.api) /flate (http://www.tinaja.com/glib/flatvue.pdf) /pstrans (http://www.tinaja.com/glib/pstrans.pdf) /advt01 (http://www.tinaja.com/advt01.asp) /amlink01 (http://www.tinaja.com/amlink01.asp) /ng1 (news:///comp.text.pdf) /ng2 (news:///comp.lang.postscript) /msc++ (http://msdn.microsoft.com/visualc/productinfo/default.asp) /degub (http://www.tinaja.com/glib/degub.pdf) /ghostscript (http://www.artifex.com/pressreleases/GS70.htm) /demox.psl (http://www.tinaja.com/glib/g9demox.psl) /demox.pdf (http://www.tinaja.com/glib/g9demox.pdf) /demo.pdf (http://www.tinaja.com/glib/g9demo.pdf) /flatvue (http://www.tinaja.com/glib/flatvue.psl) /pdfrefman (http://partners.adobe.com/asn/developer/acrosdk/docs.html) /psrefman (http://partners.adobe.com/asn/developer/technotes/postscript.html) /pdfmrm (http://partners.adobe.com/asn/developer/acrosdk/docs.html) /tipdf (http://partners.adobe.com/asn/developer/acrosdk/docs.html) /asdk (http://partners.adobe.com/asn/developer/acrosdk) /mtcr (http://support.adobe.com/devsup/devsup.nsf/docs/51864.htm) /flatvue1 (http://www.tinaja.com/psutils/flatvue1.psl) /acrob01 (http://www.tinaja.com/acrob01.asp) /post01 (http://www.tinaja.com/post01.asp) /info01 (http://www.tinaja.com/info01.asp) /gurgrm01 (http://www.tinaja.com/gurgrm01.asp) { /tilley (http://www.tilleyfoundation.com) /mnglobal (http://www.mnglobal.com/energy/pg2.htm) /keely (http://www.keelynet.com) /evolve (http://www.evolvedtechnology.com) /hack64 (http://www.tinaja.com/glib/hack64.pdf) /hackar3 (http://www.tinaja.com/glib/hackar3.pdf) /resbn58 (http://www.tinaja.com/glib/resbn58.pdf) /bppt (http://www.batterypoweronline.com) /muse112 (http://www.tinaja.com/glib/muse112.pdf) /muse113 (http://www.tinaja.com/glib/muse113.pdf) /energfun (http://www.tinaja.com/glib/energfun.pdf) /bashpseu (http://www.tinaja.com/glib/bashpseu.pdf) /adobe (http://www.adobe.com) /netscape (http://www.netscape.com) /gallypsl (http://www.tinaja.com/galley1.psl) /gallypdf (http://www.tinaja.com/galley1.pdf) /atn5150 (http://partners.adobe.com/asn/developer/acrosdk/docs/createpdfapi/pdfmarkReference.pdf) /nutour (http://www.tinaja.com/bargains/nutour02.pdf) /nutoursource (http://www.tinaja.com/bargains/nutour02.psl) /bwhistle (http://www.tinaja.com/glib/bwhistle.pdf) /gonzo1 (http://www.tinaja.com/post01.asp#gonzo) /barg01 (http://www.tinaja.com/barg01.asp) /weblib01 (http://www.tinaja.com/weblib01.asp) /gurgrm01 (http://www.tinaja.com/gurgrm01.asp) /z1 (http://www.tinaja.com/bargains/thumb/albradz2.jpg) /z2 (http://www.tinaja.com/bargains/sbtesteq.asp) /z3 (http://www.tinaja.com/images/bargs/albrad02.jpg) /z4 (http://www.tinaja.com/bargains/thumb/tutenaz2.jpg) /z5 (http://www.tinaja.com/bargains/sbphone.asp) /z6 (http://www.tinaja.com/images/bargs/tutena02.jpg) /sourceme (http://www.tinaja.com/glib/gallery.psl) /sourceme2 (http://www.tinaja.com/glib/autourl.psl) } pop >> {mark exch /eurl cvx ] cvx def} forall %%%%%%%%%%%%%%%% New colorizer patches %%%%%%%%%%%%%%%%%% /boxgrays 0.899 def /grayshade boxgrays def /mastergray boxgrays def /staytint {0.33 setgray} def /staytint1 {0.25 setgray} def /showadgrays true def /red {0 settint} def /Zmacro {staytint /ypos ypos 2 add def 72 300 div setlinewidth xpos ypos moveto txtwide 0 rlineto stroke /ypos ypos -2 add def tintoff} def % hair rule /amacro {(zy0) stringmacro /ypos ypos ypara add def 0.33 setgray } def % start drop cap /bmacro {(iFy1) stringmacro /ypos ypos ypara add def black} def % finish drop cap % Gonzo character colorizer /blueon {mark /blue cvx 0.33 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /blueoff {mark /beige cvx 0 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton {mark 0.33 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton1 {mark 0.25 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton1b {mark beige cvx % try for aqua after url??? 0.25 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton1a {mark /aqua cvx % try for aqua after url??? 0.25 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton1p {mark /burple cvx % try for aqua after url??? 0.25 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton1r {mark /red cvx % try for aqua after url??? 0.25 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton1a {mark /aqua cvx % try for aqua after url??? 0.25 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tinton1b {mark /beige cvx % try for beige after url??? 0.25 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def /tintoff {mark 0 /setgray cvx] cvx printlist exch 3 index exch put exch 1 add exch} def %%%%%%%%%%%%%% COMPACT VERSION OF COLORIZER II %%%%%%%%%%%%%%%%%%%%%% /settint {dup /currenttint exch store 5.999 mul dup floor cvi /&cbar exch store dup floor sub /&cwt exch store [ {/setgray [ /dup cvx 0.3 &cwt 0.59 mul add /ge cvx [1 /exch cvx &cwt 0.59 mul 0.30 add /sub cvx 1 &cwt sub 0.59 mul 0.11 add /div cvx /dup cvx 1 &cwt sub /mul cvx &cwt /add cvx /exch cvx ] cvx [ &cwt 0.59 mul 0.3 add /div cvx /dup cvx &cwt /mul cvx 0] cvx /ifelse cvx /setrgbcolor cvx] cvx /def cvx} {/setgray [/dup cvx 0.59 1 &cwt sub 0.3 mul add /ge cvx [1 &cwt sub 0.3 mul 0.59 add /sub cvx &cwt 0.3 mul 0.11 add /div cvx /dup cvx &cwt /mul cvx 1 &cwt sub /add cvx /exch cvx 1 /exch cvx] cvx [1 &cwt sub 0.3 mul 0.59 add /div cvx /dup cvx 1 &cwt sub /mul cvx /exch cvx 0] cvx /ifelse cvx /setrgbcolor cvx] cvx /def cvx} {/setgray [/dup cvx 0.59 &cwt 0.11 mul add /ge cvx [&cwt 0.11 mul 0.59 add /sub cvx 1 &cwt sub 0.11 mul 0.30 add /div cvx /dup cvx 1 &cwt sub /mul cvx &cwt /add cvx 1 /exch cvx] cvx [0 /exch cvx &cwt 0.11 mul 0.59 add /div cvx /dup cvx &cwt /mul cvx] cvx /ifelse cvx /setrgbcolor cvx] cvx /def cvx} {/setgray [/dup cvx 0.59 1 &cwt sub mul 0.11 add /ge cvx [1 &cwt sub 0.59 mul 0.11 add /sub cvx &cwt 0.59 mul 0.30 add /div cvx /dup cvx &cwt /mul cvx 1 &cwt sub /add cvx 1] cvx [0 /exch cvx 1 &cwt sub 0.59 mul 0.11 add /div cvx /dup cvx 1 &cwt sub /mul cvx /exch cvx] cvx /ifelse cvx /setrgbcolor cvx] cvx /def cvx} {/setgray [/dup cvx 0.11 &cwt 0.30 mul add /ge cvx[&cwt 0.30 mul 0.11 add /sub cvx 1 &cwt sub 0.30 mul 0.59 add /div cvx /dup cvx 1 &cwt sub /mul cvx &cwt /add cvx /exch cvx 1] cvx [ &cwt 0.30 mul 0.11 add /div cvx /dup cvx &cwt /mul cvx /exch cvx 0 /exch cvx ] cvx /ifelse cvx /setrgbcolor cvx ] cvx /def cvx} {/setgray [ /dup cvx 0.30 1 &cwt sub 0.11 mul add /ge cvx[ 1 /exch cvx 1 &cwt sub 0.11 mul 0.30 add /sub cvx &cwt 0.11 mul 0.59 add /div cvx /dup cvx &cwt /mul cvx 1 &cwt sub /add cvx ] cvx [ 1 &cwt sub 0.11 mul 0.30 add /div cvx /dup cvx 1 &cwt sub /mul cvx 0 /exch cvx] cvx /ifelse cvx /setrgbcolor cvx ] cvx /def cvx} ] &cbar get exec exec} bind def /beige {0.10 settint} def % examples of convenience operators /aqua {0.52 settint} def /blue {0.67 settint} def /lime {0.44 settint} def /burple {0.75 settint} def %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /guru { gonzo begin ps.util.1 begin printerror nuisance begin} def % guru % activate gonzo utilities 50 50 10 setgrid % create grid % 56 61 showgrid /setpagefonts { /cstretch 0.015 def /sstretch 0.015 def /font0 /StoneSans-Bold 1.6 gonzofont /font1 /StoneSans 0.95 gonzofont /font2 /StoneSans [0.95 0 0.25 0.95 0 0 ] gonzofont /font4 /StoneSans 0.85 gonzofont /font3 /StoneSans-Bold 0.85 gonzofont /font6 /StoneSans-Bold 0.85 gonzofont /font7 /StoneSans-Bold 1.05 gonzofont % subheaders /font8 /StoneSans-Bold [0.65 0 0 0.65 0 0.4] gonzofont /txtwide 36 store /yinc 1.2 store /kern 0.1 store /pm 1.5 store aqua 0.33 setgray font1 black /amacro { mark /aqua cvx 0.33 /setgray cvx ] cvx printlist exch 3 index exch % stuff into gonzo printlist put exch 1 add exch } def /bmacro { mark /black cvx ] cvx printlist exch 3 index exch % stuff into gonzo printlist put exch 1 add exch } def /shiftin {xpos /xposhold exch store /xpos xpos 3 add store} def /shiftout {/xpos xposhold store} def /texttop 51 store /textleft 3 store /cmacro {aqua 0.25 setgray (znhL7) stringmacro /xpos xpos 1.7 sub store /ypos ypos .1 sub def } def % left title /dmacro {black (pL1hz) stringmacro /xpos xpos 1.7 add store /ypos ypos .1 add def} def % normal text after centered title /fmacro % try and fake | {mark /gsave cvx /currentpoint cvx /moveto cvx 0.1 /setlinewidth cvx 0 0.65 /rlineto cvx /stroke cvx /grestore cvx ] cvx printlist exch 3 index exch put % stuff into gonzo printlist exch 1 add exch % increment gonzo list count } def } def setpagefonts % -2 50.5 (optional header here \274) cl %% Set document opening conventions. Note DOCVIEW limited. [/CropBox [0 0 520 620] % set the wierd size /PAGES pdfmark [ {Catalog} << /ViewerPreferences << /FitWindow true /CenterWindow true >> /PageLayout /OneColumn % continous /Pagemode /UseNone % no thumbs /View [/XYZ null null 1 ] % force 100% >> /PUT pdfmark %%%%%%%%%%%%%%%%% START DEMO ART (not in use) %%%%%%%%%%%%%%%% %%% Hand patching Info: % next available variable is /GS3 % transparency gstate is object 2 % contents stream is object 18 gets q /GS3 gs (xstuff) Q % be sure to q Q bracket to localize % resources stream is object 19 gets /GS3 2 0 R /transoverlay { % make a new graphics state [ /_objdef {newgsstate} /type /dict /OBJ pdfmark % fill the new overlay graphics state - See PDF manual for details [ {newgsstate} << /Type /ExtGState /ca 0.5 % fill transparency is 0.5 /CA 0.5 % stroke transparency is 0.5 /BM /Normal /AIS false /OP false /OPM 1 /op true >> /PUT pdfmark % start a Begin Picture graphics overlay subroutine... [ /BBox [0 0 1000 1000 ] /_objdef {overlaypix} /BP pdfmark % fill the Begin Picture graphics overlay Xobject subroutine... 0 0.5 1 setrgbcolor % on the aqua side of blue 4 4 6 6 rectfill % complete the Begin Picture graphics overlay Xobject... [ /EP pdfmark } def % Write a two squares program... /twosquares { gsave translate 1 0.5 0 setrgbcolor % red side of orange 2 2 6 6 rectfill % do background opaque box [ {overlaypix} /SP pdfmark % show foreground transparent box grestore} def % Distill the two squares program. Initially use a BARE Distiller Job % Options that has no compression, no embedded fonts, and little else save /snap1 exch store %%% transoverlay % create new objects %%% 14 17.5 twosquares snap1 restore %%%%%%%%%%%% END DEMO %%%%%%% %%%%%%%%%%%% PHOTO INSERTS %%%%%%%%%% % When photos are needed, they are inserted here. Comment out otherwise. %%%%%%%%% photo links %%%%%%%%% /pixfilename1 (C:\\windows\\desktop\\aaraw_pix\\flashfix.jpg) def /figure1 {12.5 37 200 200 pixfilename1 jpegimageproc} def % image link /pixfilename3 (C:\\windows\\desktop\\aaraw_pix\\dintcjx1.jpg) def /figure3 {12.5 0 225 202 pixfilename3 jpegimageproc} def % image link /hotspot1 { 0 0 20.5 14.3 (http://www.tinaja.com/images/bargs/marcon01.jpg) setareaurl} def /hotspot3 { 12.5 0 30 15.5 (http://www.tinaja.com/images/bargs/dintcj01.jpg) setareaurl} def /photoscale 0.075 store /jpegimageproc { % hoffset voffset hres vres save /snap2 exch def /infilename exch store % grab passed pix file /vpixels exch store /hpixels exch store translate % adjust position for final figure ??? electronics begin /DeviceRGB setcolorspace % pick color model 0 0 translate % set page position hpixels vpixels scale % magnify unit square photoscale dup scale /infile infilename (r) file def % establish input read file /Data {infile /DCTDecode filter} def % define a data source << % start image dicationary /ImageType 1 % always one /Width hpixels % JPEG width in pixels /Height vpixels % JPEG height in pixels /ImageMatrix [hpixels 0 0 vpixels neg 0 vpixels ] /DataSource Data % proc to get filtered JPEG /BitsPerComponent 8 % color resolution /Decode [0 1 0 1 0 1] % per red book 4.10 >> image % call the image operator end ypos snap2 restore /ypos exch def } def %%%%%%%%%%%%%%%%%%%%%% HOTSPOTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % manually positioned area url click.. /setareaurl { /cururlname exch store % save the url string /ury exch store /urx exch store /lly exch store /llx exch store mark % start pdfmark /Rect [ llx lly urx ury] /Border [ 0 0 0] % [0 0 0 ] = none; [0 0 2] = debug /Color [ .7 0 0 ] /Action <> /Subtype /Link /ANN % annotation type pdfmark % call pdf operators } def %%%%%%%%%%%%% /burpwide 29.5 store /burplebox3 {save /burp1 exch store xpos ypos translate -1 .2 mt 3.5 yinc mul .4 add pd burpwide pr 3.5 yinc mul .4 add pu closepath 0.9 setgray fill burp1 restore } def /burplebox2 {save /burp1 exch store xpos ypos translate -1 .2 mt 2.5 yinc mul .4 add pd burpwide pr 2.5 yinc mul .4 add pu closepath 0.9 setgray fill burp1 restore } def /burplebox2.5 {save /burp1 exch store xpos ypos translate -1 .2 mt 3 yinc mul .4 add pd burpwide pr 3 yinc mul .4 add pu closepath 0.9 setgray fill burp1 restore } def /burplebox4 {save /burp1 exch store xpos ypos translate -1 .2 mt 4.5 yinc mul .4 add pd burpwide pr 4.5 yinc mul .4 add pu closepath 0.9 setgray fill burp1 restore } def /burplebox4.5 {save /burp1 exch store xpos ypos translate -1 .2 mt 5 yinc mul .4 add pd burpwide pr 5 yinc mul .4 add pu closepath 0.9 setgray fill burp1 restore } def /burplebox5 {save /burp1 exch store xpos ypos translate -1 .2 mt 5.5 yinc mul .4 add pd burpwide pr 5.5 yinc mul .4 add pu closepath 0.9 setgray fill true {special5 } if burp1 restore } def /burplebox6 { save /burp1 exch store xpos ypos translate -1 .2 mt 6.5 yinc mul .4 add pd burpwide pr 6.5 yinc mul .4 add pu closepath 0.9 setgray fill burp1 restore } def /burplebox7.5 {save /burp1 exch store xpos ypos translate -1 .2 mt 8 yinc mul .4 add pd burpwide pr 8 yinc mul .4 add pu closepath 0.9 setgray fill burp1 restore } def /burplebox8 {save /burp1 exch store xpos ypos translate -1 .2 mt 8.5 yinc mul .4 add pd burpwide pr 8.5 yinc mul .4 add pu closepath 0.9 setgray fill burp1 restore } def /burplebox9 {save /burp1 exch store xpos ypos translate -1 .2 mt 9.5 yinc mul .4 add pd burpwide pr 9.5 yinc mul .4 add pu closepath 0.9 setgray fill burp1 restore } def /burplebox15.5 {save /burp1 exch store xpos ypos translate -1 .2 mt 16 yinc mul .4 add pd burpwide pr 16 yinc mul .4 add pu closepath 0.9 setgray fill burp1 restore } def /burplebox17 {save /burp1 exch store xpos ypos translate -1 .2 mt 17.5 yinc mul .4 add pd burpwide pr 17.5 yinc mul .4 add pu closepath 0.9 setgray fill burp1 restore } def /burplebox20 {save /burp1 exch store xpos ypos translate -1 .2 mt 20.5 yinc mul .4 add pd burpwide pr 20.5 yinc mul .4 add pu closepath 0.9 setgray fill burp1 restore } def /burplebox26.5 {save /burp1 exch store xpos ypos translate -1 .2 mt 27 yinc mul .4 add pd burpwide pr 27 yinc mul .4 add pu closepath 0.9 setgray fill burp1 restore } def /burplebox36 {save /burp1 exch store xpos ypos translate -1 .2 mt 36.5 yinc mul .4 add pd burpwide pr 36.5 yinc mul .4 add pu closepath 0.9 setgray fill burp1 restore } def %%%%%%%%%%% figure 1 routine % autopositions on box6 %%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%% QUARTIC FIVE-POINT FIT %%%%%%%%%%%%%% /figure3 { save /snap3 exch store % we use an earlier and cruder method here translate 0.9 dup scale % fit a quartic to five data points % points are 0,0 x1,y1, x2,y2, x3,y3 and 1,1 % seek general solution. % y = ax4 + bx3 + cx2 + dx + e no e since y=0 at x=0 % 1 = a + b + c + d at x = 1 EQUATION AA % a = 1 - b - c - d % egn I % a(x1)4 + b(x1)3 + c(x1)2 + d(x1) = (y1) % evaluating first point % a(x2)4 + b(x2)3 + c(x2)2 + d(x2) = (y2) % evaluating second point % a(x3)4 + b(x3)3 + c(x3)2 + d(x3) = (y3) % evaluating third point % scale to clean a % a + b/(x1) + c/(x1)2 + d(x1)3 = (y1)/(x1)4 % divide by (x1)4 % a + b/(x2) + c/(x2)2 + d(x2)3 = (y2)/(x2)4 % divide by (x2)4 % a + b/(x3) + c/(x3)2 + d(x3)3 = (y1)/(x3)4 % divide by (x3)4 % reduce a with eqn I % 1 - b - c - d + b/(x1) + c/(x1)2 + d(x1)3 = (y1)/(x1)4 % substituting for a % 1 - b - c - d + b/(x2) + c/(x2)2 + d(x2)3 = (y2)/(x1)4 % substituting for a % 1 - b - c - d + b/(x3) + c/(x3)2 + d(x3)3 = (y3)/(x1)4 % substituting for a % rearranging % b (1-(x1))/(x1) + c (1-(x1)2)/(x1)2 + d (1-(x1)3)/(x1)3 = (y1)/(x1)4 - 1 % b (1-(x2))/(x2) + c (1-(x2)2)/(x2)2 + d (1-(x2)3)/(x2)3 = (y2)/(x2)4 - 1 % b (1-(x3))/(x3) + c (1-(x3)2)/(x3)2 + d (1-(x3)3)/(x3)3 = (y3)/(x3)4 - 1 % simplifying variables % f1 = (1-(x1))/(x1) % f2 = (1-(x1)2)/(x1)2 % f3 = (1-(x1)3)/(x1)3 % f4 = (y1)/(x1)4 - 1 /f1 { 1 x1 sub x1 div } store /f2 { 1 x1 dup mul sub x1 dup mul div } store /f3 { 1 x1 dup dup mul mul sub x1 dup dup mul mul div } store /f4 { y1 x1 dup mul dup mul div 1 sub } store % g1 = (1-(x2))/(x2) % g2 = (1-(x2)2)/(x2)2 % g3 = (1-(x2)3)/(x2)3 % g4 = (y2)/(x2)4 - 1 /g1 { 1 x2 sub x2 div } store /g2 { 1 x2 dup mul sub x2 dup mul div } store /g3 { 1 x2 dup dup mul mul sub x2 dup dup mul mul div } store /g4 { y2 x2 dup mul dup mul div 1 sub } store % h1 = (1-(x3))/(x3) % h2 = (1-(x3)2)/(x3)2 % h3 = (1-(x3)3)/(x3)3 % h4 = (y3)/(x3)4 - 1 /h1 { 1 x3 sub x3 div } store /h2 { 1 x3 dup mul sub x3 dup mul div } store /h3 { 1 x3 dup dup mul mul sub x3 dup dup mul mul div } store /h4 { y3 x3 dup mul dup mul div 1 sub } store % b(f1) + c(f2) + d(f3) = (f4) % b(g1) + c(g2) + d(g3) = (g4) % b(h1) + c(h2) + d(h3) = (h4) % unify b % b + c(f2/f1) + d(f3/f1) = (f4)/(f1) % b + c(g2/g1) + d(g3/g1) = (g4)/(g1) % b + c(h2/h1) + d(h3/h1) = (h4)/(h1) % simplify variables % p1 = f2/f1 % p2 = f3/f1 % p3 = f4/f1 /p1 { f2 f1 div} store /p2 { f3 f1 div} store /p3 { f4 f1 div} store % q1 = g2/g1 % q2 = g3/g1 % q3 = g4/g1 /q1 { g2 g1 div} store /q2 { g3 g1 div} store /q3 { g4 g1 div} store % r1 = h2/h1 % r2 = h3/h1 % r3 = h4/h1 /r1 { h2 h1 div} store /r2 { h3 h1 div} store /r3 { h4 h1 div} store % b + c(p1) + d(p2) = (p3) % eqn II % b + c(q1) + d(q2) = (q3) % eqn III % b + c(r1) + d(r2) = (r3) % eqn IV % subtract eqn III from II and eqn IV from III % c((p1)-(q1)) + d((p2)-(q2) = (p3)-(q3) % c((q1)-(r1)) + d((q2)-(r2) = (q3)-(r3) % simplify variables % s1 = (p1) - (q1) % s2 = (p2) - (q2) % s3 = (p3) - (q3) /s1 { p1 q1 sub} store /s2 { p2 q2 sub} store /s3 { p3 q3 sub} store % t1 = (q1) - (r1) % t2 = (q2) - (r2) % t3 = (q3) - (r3) /t1 { q1 r1 sub} store /t2 { q2 r2 sub} store /t3 { q3 r3 sub} store % c(s1) + d(s2) = (s3) % c(t1) + d(t2) = (t3) % unify c % c + d (s2)/(s1) = (s3)/(s1) % c + d (t2)/(t1) = (t3)/(t1) % simplify variables % u1 = (s2)/(s1) % u2 = (s3)/(s1) /u1 { s2 s1 div} store /u2 { s3 s1 div} store % v1 = (t2)/(t1) % v2 = (t3)/(t1) /v1 { t2 t1 div} store /v2 { t3 t1 div} store % c + d(u1) = (u2) % eqn V % c + d(v1) = (v2) % eqn VI % subtract VI from V % d ((u1) - (v1)) = (u2) - (v2) % AND SOLVE FOR DDD % d = (u2) - (v2)/((u1) - (v1)) % DDDDDDDDD /dd { u2 v2 sub u1 v1 sub div } store % find c from eqn V % c + d(u1) = (u2) % c = (u2) - d(u1) <------- CCCCC /cc {u2 dd u1 mul sub} store % find b from eqn II % b + c(p1) + d(p2) = (p3) % b = (p3) - c(p1) - d(p2) <------- BBBBB /bb { p3 cc p1 mul sub dd p2 mul sub } store % and a from eqn I % a = 1 - b - c - d /aa {1 bb sub cc sub dd sub} store % ========== /x1 0.2 store /y1 0.1 store /x2 0.4 store /y2 0.3 store /x3 0.7 store /y3 0.8 store gsave line2 staytint 0 0 mt 20 pu 20 pr 20 pd closepath 0.9 setgray fill grestore 20 20 showgrid 0.55 setgray line3 0 0 mt 20 u 20 r 20 d 20 l staytint 0 0 mt dot 1 20 mul 1 20 mul mt dot x1 20 mul y1 20 mul mt dot x2 20 mul y2 20 mul mt dot x3 20 mul y3 20 mul mt dot % line1 0 0 mt 20 20 lineto stroke line2 0 0 moveto 0 0.01 1 { /xx exch store xx 20 mul xx dup mul dup mul aa mul xx dup dup mul mul bb mul add xx dup mul cc mul add xx dd mul add 20 mul lineto } for stroke % aa == bb == cc == dd == snap3 restore } store %%%%%%%%%%%%%%% end figure3 /special5 {gsave 4 -5.85 translate line1 black 0.3 0 mt 0.3 l 5.2 u 0.3 r 13.2 0 mt 0.3 r 5.2 u 0.3 l 15.3 0 mt 0.3 l 5.2 u 0.3 r 18.3 0 mt 0.3 r 5.2 u 0.3 l grestore } store /xkernon {/kernsave kern store /kern 0.18 store } def /xkernoff {/kern kernsave store} def /pagenum 1 store /startnewpage { black beige 0.35 setgray 21 -2.5 (|3\320|j) pagenum 10 string cvs mergestr (|j\320) mergestr cc aqua showpage %% start next page /pagenum pagenum 1 add store 50 50 10 setgrid % create grid setpagefonts font1 textleft texttop } def /su {surl font6} store /to {tinton1 font6} store /tx {tintoff font1} store /tabs [11 15] store /font7 /helvetica [0.7 0 0 0.7 0 0.5] gonzofont font1 aqua 0.33 setgray font0 20 47.3 0.7 add 1 sub 1 add (Exact Data Point Fitting) cc 20 45.3 0.7 add (Using Power Curves) cc black font2 textleft 43 0.3 add % this one only need |h below (|/aqua |/staytint1 |3Don Lancaster Synergetics, Box 809, Thatcher, AZ 85552 copyright c2003 as |/surl |6GuruGram|1|/gurgrm01 |/tinton1 |6#18 |/surl http://www.tinaja.com|/tinaja |/surl don@tinaja.com|/maildon (928) 428-4073 |/aqua |/black |a|0W|b|1hat is the "best" way to draw a smooth curve through a set of data points? For most |/su PostScript|1|/post01 and computer graphics uses, |/su cubic splines|1|/cubic01 end up best, owing to their ease of control. We've seen lots of details on these in our |/su cubic|/cubic01 |/su spline|1|/cubic01 library. And especially our |/su 4-point Bezier Point Fitter|1|/muse145 , its underlying math analysis |/su BEZ4PTS.PDF|1|/bez4pts and our Bezier curve through fuzzy data |/su FUZZYBEZ.PSL|1|/fuzzybez . |h But an ordinary power or |/su Taylor Series|1|/muse148 series can sometimes be used to exactly fit any given set of data points. Which can end up a cleaner and simpler solution for certain apps. The good news is that\274 |6|/shiftin |/burplebox2 |/staytint1 |h You can always fit n data points by using a n-1 power series. |1|/shiftout |/aqua |/black |h The bad news is that if the points are noisy or otherwise not well behaved, the intermediate curve values may end up wildly different than expected. |h The theory is simple enough: you can fit a straight line through any two points. To fit a third point off the curve, add a piece of a second order parabola. To fit a fourth point, use a parabola and then adjust the parabola with a cubic. |h I've added a new |/su CURVEFT3.PSL|1|/curveft3 utility to my |/su PostScript|1|/post01 and |/su Math Stuff|1|/math01 library pages. This fits up to ten data points with an appropriate power series. To use one of the routines, you enter your data, resave as an ordinary textfile under a new name, and then send to |/su Acrobat Disillter|1|/adobe . A plot is returned as a .PDF file, and the magic coefficients are found in a companion log file. |h Lets look at a five data point fit as an example. By the above rule, we will need a fourth order equation\274 |1|/shiftin |/burplebox2 |h a|j(x)|74|1 + b|j(x)|73|1 + c|j(x)|72|1 + d|j(x) + e |j=|j y |1|/shiftout |/aqua |/black ) cl startnewpage (In interests of sanity, we will usually |/to scale|/tx our values so that the first data point is at |/to 0,0|/tx and our final data point |/to 1,1|/tx . This forces |/to e|j=|j0|/tx and possibly gives us other simplifications. Now, all we have to do is find the values for |/to a|/tx , |/to b|/tx , |/to c|/tx , and |/to d|/tx , and we are home free. |h Let's use data points of |/to 0.0|j,|j0.0|/tx and |/to 0.2|j,|j0.1|/tx and |/to 0.4|j,|j0.3|/tx and |/to 0.7|j,|j0.8|/tx and |/to 1.0|j,|j1.0|/tx as an example. The game plan is to create four equations in four unknowns by inserting |/to known|/tx data point values of |/to (x)|/tx and |/to (y)|/tx into the above fourth order power series equation. Since there are possible subtle advantages to using your |/to highest data points first|/tx , we will do so. And come up with\274 |1|/shiftin |/burplebox4 1.0000|ja + 1.000|jb + 1.000|jc + 1.000|jd = 1.000 0.2401|ja + 0.343|jb + 0.490|jc + 0.700|jd = 0.800 0.0256|ja + 0.064|jb + 0.160|jc + 0.400|jd = 0.300 0.0016|ja + 0.008|jb + 0.008|jc + 0.200|jd = 0.100 |1|/shiftout |/aqua |/black Let's change the notation by putting it in a simpler |/to matrix |/tx form\274 |1|/shiftin |/burplebox5 |h 1.0000 1.000 1.000 1.000 1.000 0.2401 0.343 0.490 0.700 0.800 0.0256 0.064 0.160 0.400 0.300 0.0016 0.008 0.008 0.200 0.100 |h |1|/shiftout |/aqua |/black There's all sorts of ways to solve |/to n|/tx linear equations in |/to n|/tx unknowns. Including simple substitution, |/su determinants|1|/muse106 , and other data reduction schemes. One useful method is known as |/su Gauss Jordan Elimination|1|/muse142 . This works by first doing a lot of repetitive "Gauss" front end work to change the matrix into this form\274 |1|/shiftin |/burplebox5 |h|/xkernon 1 |kj01 |kj02 |kj03 k00 0 1 |kj12 |kj13 k01 0 0 1 |kj23 k02 0 0 0 1 k03 |h|/xkernoff |1|/shiftout |/aqua |/black The |/to j|/tx and |/to k|/tx values are what you happen to get when you complete the "Gauss" transformations. From here, you then do more repetitive "Jordan" front end work to get this final |/to reduced|/tx form\274 |1|/shiftin |/burplebox5 |h 1 0 0 0 a 0 1 0 0 b 0 0 1 0 c 0 0 0 1 d |h| |1|/shiftout |/aqua |/black ) cl startnewpage (After doing the front end dogwork, you can now view the |/to a|/tx , |/to b|/tx , |/to c|/tx , and |/to d|/tx results |/to by |/to inspection|/tx ! Simply by looking at the right matrix. |h The key two rules used to cause this reduction are\274 |^|/shiftin |/burplebox2 |/staytint1 |6Any matrix row can have all values multiplied or divided by any nonzero constant without changing the results. |1|/shiftout |/aqua |/black And\274 |6|/shiftin |/burplebox2 |/staytint1 Any matrix row can have all its values subtracted from any other row without changing the results. |1|/shiftout |/aqua |/black |h This is just the same as saying you can |/to nonzero|/tx multiply or divide everything in an equation by a constant without changing the results. And you can subtract two equations from each other |/to term-for-term|/tx without changing the results. |h To do the reduction, you scale to make j00 unity. Trivial in this case since it already is. Then you force j10 to zero by subtracting j10 times the top row from the second row. Then you force j11 to unity by dividing its row by j11. The process repeats till the principle diagonal is unity and everything below and left is precisely zero. |h You then work |/to up|/tx the right side to do the |/to Jordan|/tx part. By making similar zero subtractions. |h Doing the actual work reveals that |/to a|j=|j-3.86905|/tx , |/to b|j=|j5.14881|/tx , |/to c|j=|j-0.755954|/tx , and |/to d|j=|j|/to 0.476191|/tx . And that our curve fitting attempt looks like this\273 ) cl 11.5 0.3 figure3 startnewpage (|c For More Help |d Example plots are included in the utility for up to a ten data point fit. The power curve fitting scheme is |/su extendable|1|/info01 and useful up to twenty points or so. But at some point PostScript's 32-bit math precision will start to create problems, so you'll want to switch to |/su JavaScript|1|/magsn01 or some other 64-bit solution. It may often be better to deal with lots of points as subgroups instead. Or to add "throwaway" points at both ends where the wilder gyrations are more likely to occur. |h Note that |/to data points are best entered in monotonic increasing order|/tx , and that |/to values very near zero or one are best avoided|/tx . This works around some of the Gauss-Jordan limitations that may crop up in more general problems. |h I started exploring this method as a means of generating gamma table lookups. But I found certain data values (as in our example) may lie outside the unity box. I instead ended up with an alternate method for gamma curve generation. Which is in our |/su Dodges & Burns|1|/dodgebur tutorial in our |/su GuruGram|1|/gurgrm01 library. The new method keeps you inside the unity box, but may slightly miss some data points. What we have looked at here remains highly useful for other data point curve fitting apps. |h Additional background along with related utilities and tutorials appears on our |/su Math Stuff|1|/math01 |/su GuruGram|1|/gurgrm01 , |/su PostScript|1|/post01 , |/su Cubic Spline|1|/cubic01 , and |/su Fonts & Bitmaps|1|/aafont01 libraries. |h Consulting assistance on any and all of these and related topics can be found at |/surl |6http://www.tinaja.com/info01.asp|1|/info01 . As can other math solutions. |h Additional |/surl |6GuruGrams|1|/gurgrm01 await your ongoing support as a |/surl |6Synergetics Partner|1|/advt01 . ) cl startnewpage %%%%%%%%%%%%%%%%%%%% % EOF