Home » Images » Image_Graph » Bug #5181
smooth_line doesn't draw a function
Details
| Submitted | 2005-08-23 04:15 UTC |
|---|---|
| From | nospam0 at malkusch dot de |
| Status | Wont fix |
| Package | Image_Graph |
| PHP Version | 5.0.3 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2005-08-23 04:15 UTC] nospam0 at malkusch dot de
Description:
------------
Have a look at <http://test.malkusch.de/smoothGraph.php>.
It is not a function. You can see the code at
<http://test.malkusch.de/smoothGraph.phps>. BTW
smooth_line doesn't antialias.
Test script:
---------------
<?php
$data = array(
0 => 10,
10 => 5,
11 => 100
);
$canvas = Image_Canvas::factory('png', array('width' => 600, 'height' => 400, 'antialias' => 'native'));
$graph = Image_Graph::factory('graph', $canvas);
$plotarea = $graph->addNew('plotarea', array('axis', 'axis'));
$dataset = Image_Graph::factory('dataset');
$plot = $plotarea->addNew('smooth_line', $dataset);
foreach ($data as $x => $y) {
$dataset->addPoint($x, $y);
}
$graph->done();
?>
Expected result:
----------------
A function.
Actual result:
--------------
A relation.
[2005-08-23 06:25 UTC] pear dot nosey at veggerby dot dk
This is not a bug (per se) it is the way the smoothing function calculates the points (it's the "only" way to create a smooth curve through these points using the implemented method - Bezier curves). If you plot the exact same graph in Excel you get... the same result.
The smoothed curves doesn't antialias because it looks like cr*p when it does (due to the high number of very short lines), I know it doesn't explicitly say so in the code but if you read between the lines and can read my mind it actuallly says so in the docs :p(http://cvs.php.net/co.php/pear/Image_Canvas/Canvas/GD.php?r=1.3). I'll fix the docs so it states this explicitly.
[2005-08-23 11:11 UTC] nospam0 at malkusch dot de
> it's the "only" way to create a smooth curve through
> these points using the implemented method - Bezier
> curves
But the result is definetly wrong. It gets even worser if
you have a look again at
<http://test.malkusch.de/smoothGraph.php>.
I don't believe that this is the only way to create a
smooth graph. Did you try any interpolation? I think it is
more important to create a function (which doesn't need to
include all data points) than a complete smooth relation.
> If you plot the exact same graph in Excel you get... the
> same result.
Excel has no importance. What about programms like maple,
or any programm which is used by an professional
statistician?
[2005-08-23 11:35 UTC] pear dot nosey at veggerby dot dk
I agree that it does not look "right", however smoothing curves are not "exact science", there are of course other algorithms fx. Bicubic splines (this issue has been touched before: http://pear.php.net/bugs/bug.php?id=3293) and I'm sure you can create an algorithm that suits your needs, but as stated in the last "post":
"The way the smoothing in Image_Graph is done is based on 2
requirements:
1) Overall smoothness
2) The curve intersects _all_ datapoints"
Maybe you can manipulate the "curvature" or roundness by messing with the smoothFactor in Image_Canvas\Tool.php (if it works I will provide a method for adjusting this): higher values the more "round" the curve will be.
I do not believe that there is anything wrong with the function (which was why I mentioned Excel, you can even try to plot the same data using the SVG canvas, where the smoothing is done natively (also Bezier) and I'll bet you that you get the same result), but as said this is not "exact science" anyway so you would have to choose an algorithm that can display your data in a way that suits you best - unfortunately the only implemented method here is Bezier curves. I'm not even sure that the solution would be to provide more methods, since the Bezier method implemented in Image_Canvas\Tool.php is only there because there is no native method, like there is in PDF, SVG and SWF (IIRC SWF uses cubic splines).
regards
Jesper