theoretical foundations of gnuplot csplines - gnuplot

Which is the theoretical method employed in the csplines smoothing algorithm available in gnuplot? Is it a piecewise least square fit with polynomials? Like a Savitzky–Golay smoothing filter or, as the name suggests, some modification of bsplines? Also: in gnuplot version 4.4 I observed an oscillatory behaviour in the interpolating curve if I employ it for double-logarithmic plots. Is that to be expected?

csplines stands for a cubic spline algorithm. You can see this by typing help csplines in gnuplot, or by looking at the source code (see the functions gen_cubic_spline and intp_cubic_spline in contour.c).
About the oscillations in cubic splines (they are to be expected in some circumstances), see this reference, or this if you can access it.

Related

How to compute shortest distances of points and curve in gnuplot?

Let's say I have a fitted curve in gnuplot (or simply sin(x) function) and file with data - points nearby the function. How to compute the distance of points from the curve and write them to the file with data in gnuplot? Is it possible to implement easily sum of squares in gnuplot? Thank you very much
Your question seems to mix two different concepts. If the curve was fitted to the points then the component term in the sum-of-squares uses the difference in y values. I.e. for a point [xi, yi] the term is (func(xi) - yi)**2.
But this is not the same thing as "distance of the point from the curve", since the nearest point on the curve may be at some different x value. The answer to that question in general requires calculus and is not something that gnuplot is designed to help you with, although if you work out the relevant equation you could use gnuplot's "fit" to find the minimum by approximation rather than by solving the differential equation analytically.
To plot the residuals after fitting
Assume data points [xi, yi] in columns 1 and 2 of file "data".
Assume fit(x) is the function you got from fitting. Then you can plot the residual for each point:
plot 'data' using 1:( (fit($1)-$2)**2 ) with linespoints

Gnuplot: How to plot heat maps on three coordinate facets to visualize 4D data

I am new to Gnuplot and unfortunately have to start with a (for me) nontrivial problem. I have X-Y-Z-Temperature data. So I have for every spatial coordinate a temperature value.
This comes somewhat closest
http://pgfplots.net/tikz/examples/contour-and-surface/
However, I would like to create a heat map (not contour) on the XY XZ and YZ plane to visualise the 4D data better (in the link it is just 3D).
So on each plane just a heat map using the same color code so that the temperatures can be compared.
Many thanks!
Toby
You can make '4d' plot with palette, e.g:
splot '3d.dat' u 1:2:3:4 palette pt 9
So you mean e.g. plotting a triedron T(x,y,z=0), T(x=0,y,z) and T(x,y=0,z) ? This should be possible with multiplot and rotating the view between each plot. This will be a fair amount of hacking, so the first question would be why you don't use other visualization software like paraview or mayavi ? These are more suited for this type of data, unless you need the flexibility of gnuplot either in terms of scripting, or in terms of plotting analytical functions on the same graph.

for loop with parametric plots in gnuplot

I am trying to plot multiple parametric curves in gnuplot 4.6.
In an earlier version (4.4?), the commands
set para
plot [-pi:pi] for [a=1:10] a*cos(t),a*sin(t)
would result in ten circles centered at the origin with radius 1, 2, ..., 10. In 4.6, the result is one circle of radius 1.
In 4.6, the commands
unset para
plot [-pi:pi] for [a=1:10] a*sin(x)
yield ten beautiful sine curves.
So, it appears that the "for" command now has a problem with parametric curve plotting, I guess.
Does anyone know of a workaround? The circle object is not useful for me: I am interested in general curves. Thanks!
The syntax ambiguity between parametric mode and iteration is a documented bug/limitation in current gnuplot versions. In the development version (4.7) a separate parametric mode is not necessary, as the required sampling variable can be explicitly described in a generic plot command:
plot for [a=1:10] [t=-10:10] '+' using (a*sin(t)):(a*cos(t))
Unfortunately that fully general syntax is not available in version 4.6. The closest I can think of is a simpler variant:
unset parametric
plot for [a=1:10] '+' using (a*sin($1)):(a*cos($1))
This works for your example case, but may not suffice for your actual use case because it conflates the sampling range on the parametric variable with the implicit plotting range on x.

How can I draw an implicit function f(x,y,z)=0 with gnuplot?

I want to draw the following implicit function with gnuplot
x**2+y**2+(z-1)**3-2
I know that maple or matlab can to this very simple but I want to use gnuplot.
Up to know I have no idea so I can't provide a starting point.
sorry
Here the result plotted with maple
According to the Gnuplot FAQ, this is not directly possible. There is a workaround for 2D-functions, but I don't see how this method can be applied to 3D graphs. I'd recommend solving the equation in Octave or some similar program and outputting the solutions to a file, which you can then feed into GnuPlot.

How to offset a cubic bezier curve?

I'm trying to create a "parrallel" bezier curve. In my attempts I've gotten close but no cigar. I'm trying to keep a solid 1px offset between the 2 curves (red,blue).
My main goal is use a edge offseting algorythm to expand/shrink a svg path.
Solution
For anyone else who is looking for a solution, I've create a AS3 version.
http://seant23.wordpress.com/2010/11/12/offset-bezier-curves/
I hope you found my math paper useful
Quadratic bezier offsetting with selective subdivision
https://microbians.com/mathcode
From wikipedia: ( http://en.wikipedia.org/wiki/B%C3%A9zier_curve )
The curve at a fixed offset from a given Bézier curve, often called an offset curve (lying "parallel" to the original curve, like the offset between rails in a railroad track), cannot be exactly formed by a Bézier curve (except in some trivial cases). However, there are heuristic methods that usually give an adequate approximation for practical purposes.
You might also see the paper indicated here:
Outline of cubic bezier curve stroke
What you ask for is called a parallel or offset curve in mathematics. The Wikipedia article (quoted above by others) on Bezier curves failed to link to the right article for "offset curve", but I've fixed that a few seconds ago. In the world of vector graphics, that same notion is called stroking the path.
In general, for cubic/Bezier curve the offset curve is a 10th order polynomial! Source: Kilgard, p. 28
If all you want to do is rasterize such offset curves, rather than compute their analytic form, you can for example look at the sources of ghostscript. You could also look at this patent application to see how NV_path_rendering does it.
If you want to covert/approximate the offset curves, then the TUG paper on MetaFog for covering METAFONT to PostScript fonts is a good reading. The METAFONT system, which predated PostScript allowed fonts to be described by the (more mathematically complex) operation of stroking, but PostScript Type 1 fonts only allow filling to be used (unlike PostScript drawings in general) for reasons of speed.
Another algorithm for approximating the offsets as (just two) Beziers (one on each side), with code in PostScript, is given in section 7 of this paper by Gernot Hoffmann. (Hat tip to someone on the OpenGL forum for finding it.)
There are in fact a lot of such algorithms. I found a 1997 survey of various algorithms for approximating offset curves. They assume the progenitor curves are Beziers or NURBS.
It's not possible in general to represent the offset of a cubic Bezier curve as a cubic Bezier curve (specifically, this is problematic when you have cusps or radius of curvature close to the offset distance). However, you can approximate the offset to any level of accuracy.
Try this:
Offset the Beziers in question (what you have already seems pretty decent)
Measure the difference between each original curve and corresponding offset curves. I'd try something like 10 samples and see if it works well.
For any offset that's outside of tolerance, subdivide (using the deCastlejau algorithm for Beziers) and iterate.
I haven't implemented an offset (because the kernels I use already have one), but this seems like something to try.

Resources