On Friday 09 December 2005 01:22 pm, Eric L. wrote:
ruby myprog.rb | gnuplot
If you need to do something more complicated (or if your OS doesn’t
support pipes), creating an object that acts as an output stream to a
gnuplot process would be fairly easy.
I already checked out gnuplot and had some problems:
It doesn’t take y2+x2=16, but instead requires you to solve for y
put in (16-x**2)**0.5, which gives you only the upper half of the
I thought, OK, I’ll make all the points in Ruby, and pipe them to
No joy – gnuplot’s interpolation between points is stupid – all but
just produce a straight line, and bezier produces cusps where there
any. I spoze I could send LOTS of points, and that might work.
Which brings up the next point – algorithm. Remember, I want the full
y2+x2=16, not the right side solved for y.
I’m thinking I start by setting the right side to 0, so it would be
y2+x2-16=0. That’s OK in this situation. Then I walk up each axis
find a point where the right side shifts from positive to negative or
versa. Interpolate, try again, interpolate again til I have a reasonably
close point. Now go out maybe 0.1 in each direction and find points. Now
calculate slopes, go out some more along that slope and do it again.
soon I’ve traced out all relevant points on a continuous curve (this
work with discontinuous curves).
Now that you see the algorithm I was contemplating, you probably
why I was hoping Ruby had a module that produces points for me