[Tioga-users] Tioga3d 0.0.1
Edwin
edder at tkwsping.nl
Sat Jun 3 16:29:24 EDT 2006
Most of the basic plotting functionality of my 3d project is finished, so
I decided to share it in the hope of some feedback :) I attached the
source code
====The Good====
The good is that the plotting functionality works. Show_plot_3d draws the
axes, and you should be able to use most default methods by putting _3d
behind them. This should work at least with all functions that expect xs
and ys coordinates (show_polyline). Methods that expect dicts (like
show_marker) should also be covered as long as they use the standard
coord-notations (at, point, x, y, xs, ys). Other methods might need custom
wrappers (like show_arrow) which aren't provided yet.
====The Bad====
I only concentrated on plotting, because I don't see a reason to use 3d
otherwise. This means that I have only concentrated on the plotting
functions and I can see no reason to support "figure only" things like
append_arc_to_path. If you disagree please let me know
Testing has been very incomplete and there are probably quite a few
functions that need customized wrappers, which I don't know about yet or
have ignored for now (like show_arrow). If you find any "bugs" please let
me know.
====The Ugly====
The way axes are handled is not nice and they don't look perfect yet. This
is mostly because I have not yet taken the dive into writing c extensions.
To be able to draw axes properly I would have to rewrite my show_axis
function in c, so I can access the PlotAxis struct.
On the plus side I wrote a more versatile show_axis method (called
show_axis_3d), which should also be usable for 2d axes. The method
basically needs an origin ([x,y] for 2d and [x,y,z] for 3d), the minimum
value of the axis, the maximum value, the direction the axis takes ([1,0]
or [1,0,0] for in the x direction) and the direction of the ticks ([0,1]
or [0,1,0] are ticks parellel to the y axis)
====Performance====
I haven't checked performance, but the easiest way to gain performance
would be by implementing the transform_coord method in c. I used the
gnuplot code as an example and we could just use their code almost
directly, although I'm not sure if you can use gpl'ed code in lgpl
projects (prob not)
====Example====
require 'tioga3d.rb'
class Test
include Tioga
include FigureConstants
def initialize
@figure_maker = FigureMaker.default
#until the 3d code is part of the official tree you will need to
initialize some constants separatedly
t.initialize_3d
t.save_dir = 'plots_out'
#for linux users
$open_command = 'xpdf'
@cube = t.def_figure( "cube" ) { cube }
@random = t.def_figure( "random" ) { random }
end
def t
@figure_maker
end
def cube
#t3d.view( 60,245 )
xs = Dvector[-1,-1,1,1,-1,-1,1,1]
ys = Dvector[-1,-1,-1,1,1,1,1,-1]
zs = Dvector[-1,1,1,1,1,-1,-1,-1]
t.show_plot_3d([xs.min-0.05, xs.max+0.05, ys.min-0.05, ys.max+0.05,
zs.min, zs.max]) {
t.append_points_to_path_3d(xs, ys, zs)
t.append_point_to_path_3d(0,0,0)
t.stroke
t.show_polyline_3d([-1,1],[-1,1],[-1,1], Red)
}
end
def random
t.show_plot_3d() {
100.times {
x = rand
y = rand
z = rand
t.show_marker_3d( 'marker' => Bullet, 'at' => [x, y, z], 'scale'
=> 0.2 )
}
t.show_marker_3d( 'marker' => Bullet,
'xs' => [0,1,0],
'ys'=> [1,0,0],
'zs' => [0,0,1],
'color' => Red )
}
end
end
Test.new
====Future====
First thing I want to do is implement the drawing of a surface from data
points. I have no experience with this type of thing, but google tells me
I should use Delaunay triangulations, if anyone knows more, please let me
know.
The easiest way to go about that is use the qhull library. This will also
finally teach me how to extend ruby programs in c. If anyone has a good
tutorial on that please let me know.
After that I'll probably want to fix/rewrite the axes (unless Bill or
Vincent find time to do it ofcourse :) )
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tioga3d.rb
Type: application/octet-stream
Size: 12816 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/tioga-users/attachments/20060603/b3b0efbe/attachment.obj
More information about the Tioga-users
mailing list