1<?php 2 3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 4 5/** 6 * Image_Graph - PEAR PHP OO Graph Rendering Utility. 7 * 8 * PHP version 5 9 * 10 * LICENSE: This library is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License as published by 12 * the Free Software Foundation; either version 2.1 of the License, or (at your 13 * option) any later version. This library is distributed in the hope that it 14 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 16 * General Public License for more details. You should have received a copy of 17 * the GNU Lesser General Public License along with this library; if not, write 18 * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19 * 02111-1307 USA 20 * 21 * @category Images 22 * @package Image_Graph 23 * @subpackage Dataset 24 * @author Jesper Veggerby <pear.nosey@veggerby.dk> 25 * @author Stefan Neufeind <pear.neufeind@speedpartner.de> 26 * @copyright 2003-2009 The PHP Group 27 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 28 * @version SVN: $Id: VectorFunction.php 291170 2009-11-23 03:50:22Z neufeind $ 29 * @link http://pear.php.net/package/Image_Graph 30 */ 31 32/** 33 * Include file Image/Graph/Dataset.php 34 */ 35require_once 'Image/Graph/Dataset.php'; 36 37/** 38 * Vector Function data set. 39 * 40 * Points are generated by calling 2 external functions, fx. x = sin(t) and y = 41 * cos(t) 42 * 43 * @category Images 44 * @package Image_Graph 45 * @subpackage Dataset 46 * @author Jesper Veggerby <pear.nosey@veggerby.dk> 47 * @author Stefan Neufeind <pear.neufeind@speedpartner.de> 48 * @copyright 2003-2009 The PHP Group 49 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 50 * @version Release: 0.8.0 51 * @link http://pear.php.net/package/Image_Graph 52 */ 53class Image_Graph_Dataset_VectorFunction extends Image_Graph_Dataset 54{ 55 56 /** 57 * The name of the X function 58 * @var string 59 * @access private 60 */ 61 var $_functionX; 62 63 /** 64 * The name of the Y function 65 * @var string 66 * @access private 67 */ 68 var $_functionY; 69 70 /** 71 * The minimum of the vector function variable 72 * @var double 73 * @access private 74 */ 75 var $_minimumT; 76 77 /** 78 * The maximum of the vector function variable 79 * @var double 80 * @access private 81 */ 82 var $_maximumT; 83 84 /** 85 * Image_Graph_VectorFunctionDataset [Constructor] 86 * 87 * @param double $minimumT The minimum value of the vector function variable 88 * @param double $maximumT The maximum value of the vector function variable 89 * @param string $functionX The name of the X function, if must be a single 90 * parameter function like fx sin(x) or cos(x) 91 * @param string $functionY The name of the Y function, if must be a single 92 * parameter function like fx sin(x) or cos(x) 93 * @param int $points The number of points to create 94 */ 95 function Image_Graph_Dataset_VectorFunction($minimumT, $maximumT, $functionX, $functionY, $points) 96 { 97 parent::__construct(); 98 $this->_minimumT = $minimumT; 99 $this->_maximumT = $maximumT; 100 $this->_functionX = $functionX; 101 $this->_functionY = $functionY; 102 $this->_count = $points; 103 $this->_calculateMaxima(); 104 } 105 106 /** 107 * Add a point to the dataset 108 * 109 * @param int $x The X value to add 110 * @param int $y The Y value to add, can be omited 111 * @param var $ID The ID of the point 112 * 113 * @return void 114 */ 115 function addPoint($x, $y = false, $ID = false) 116 { 117 } 118 119 /** 120 * Gets a X point from the dataset 121 * 122 * @param var $x The variable to apply the X function to 123 * 124 * @return var The X function applied to the X value 125 * @access private 126 */ 127 function _getPointX($x) 128 { 129 $functionX = $this->_functionX; 130 return $functionX ($x); 131 } 132 133 /** 134 * Gets a Y point from the dataset 135 * 136 * @param var $x The variable to apply the Y function to 137 * 138 * @return var The Y function applied to the X value 139 * @access private 140 */ 141 function _getPointY($x) 142 { 143 $functionY = $this->_functionY; 144 return $functionY ($x); 145 } 146 147 /** 148 * Reset the intertal dataset pointer 149 * 150 * @return var The first T value 151 * @access private 152 */ 153 function _reset() 154 { 155 $this->_posX = $this->_minimumT; 156 return $this->_posX; 157 } 158 159 /** 160 * The interval between 2 adjacent T values 161 * 162 * @return var The interval 163 * @access private 164 */ 165 function _stepX() 166 { 167 return ($this->_maximumT - $this->_minimumT) / $this->count(); 168 } 169 170 /** 171 * Calculates the X and Y extrema of the functions 172 * 173 * @return void 174 * @access private 175 */ 176 function _calculateMaxima() 177 { 178 $t = $this->_minimumT; 179 while ($t <= $this->_maximumT) { 180 $x = $this->_getPointX($t); 181 $y = $this->_getPointY($t); 182 $this->_minimumX = min($x, $this->_minimumX); 183 $this->_maximumX = max($x, $this->_maximumX); 184 $this->_minimumY = min($y, $this->_minimumY); 185 $this->_maximumY = max($y, $this->_maximumY); 186 $t += $this->_stepX(); 187 } 188 } 189 190} 191 192?> 193