Ruby 3D Math libraries?

B

Bart Braem

Hello,

Does anyone know good Ruby 3D Math libraries? I found Math3D
(<http://raa.ruby-lang.org/project/math3d/>) but I can not get it working,
ruby extconf.rb fails:
$ ruby -r mkmf extconf.rb
checking for atan() in -lm... no
No atan() in -lm
*** extconf.rb failed ***

This is after I commented the following line, which made the configuration
fail too:
CFLAGS << " -Wall -Wno-comment"

The Alg3D library is not bad, but it does not contain everything from the 3D
Math library. E.g. rotation is missing, which is something I need.

Regards,
Bart
 
B

Bill Kelly

From: "Bart Braem said:
Does anyone know good Ruby 3D Math libraries? I found Math3D
(<http://raa.ruby-lang.org/project/math3d/>) but I can not get it working,
ruby extconf.rb fails:
$ ruby -r mkmf extconf.rb
checking for atan() in -lm... no
No atan() in -lm
*** extconf.rb failed ***

This is after I commented the following line, which made the configuration
fail too:
CFLAGS << " -Wall -Wno-comment"

Are you possibly on Windows? I recall needing to make a few
tweaks here and there to Math3D to get it to compile on
Windows.

Here are the changes:

diff -u orig/rb_math3d.c rb_math3d.c
--- orig/rb_math3d.c 2005-02-08 01:10:14.189772800 -0800
+++ rb_math3d.c 2005-02-08 02:10:09.669819200 -0800
@@ -4,8 +4,15 @@
* (e-mail address removed)
************************************
*/
+#if defined(_WIN32)
+#define _USE_MATH_DEFINES
+#endif
#include "ruby.h"
#include <math.h>
+#if defined(_WIN32)
+#undef FAR
+#undef NEAR
+#endif
#include "math3d_native.h"


Hope this helps,

Bill
 
B

Bart Braem

Paul said:
For some reason, you have a very limited math library on your system.
Chances are you will succeed in the compilation if you will replace your
math library with a complete one.

It is a little difficult to believe there is a math library without
"atan()", and it implies there is something basically wrong with the one
installed on your system.

My point is that the Math3D library is not the problem, it is solely a
problem with your native-code math library, on which Math3D depends.

Strange, but I noticed my libm.a is not in my path. I'll fix that first...

Bart
 
B

Bart Braem

Bill said:
Are you possibly on Windows?  I recall needing to make a few
tweaks here and there to Math3D to get it to compile on
Windows.

I'm working on linux, but thanks for the information!

Bart
 
B

Bart Braem

Paul said:
For some reason, you have a very limited math library on your system.
Chances are you will succeed in the compilation if you will replace your
math library with a complete one.

I removed the check for the function and now the Makefile is perfectly
generated and make works flawlessly. Make test fails however:

make test
ruby test.rb
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require__': ./tests/Vector.tests.rb:556: no .<digit> floating literal
anymore; put 0 before dot (SyntaxError)
expected = vec.to_a.inject(0) {|x,y| x+(y*y)}.**(.5)
^
../tests/Vector.tests.rb:556: parse error, unexpected '.', expecting ')'
expected = vec.to_a.inject(0) {|x,y| x+(y*y)}.**(.5)
^
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
from test.rb:30
from /usr/lib/ruby/1.8/find.rb:39:in `find'
from /usr/lib/ruby/1.8/find.rb:38:in `catch'
from /usr/lib/ruby/1.8/find.rb:38:in `find'
from test.rb:20
make: *** [test] Error 1

Turning .5 into 0.5 fixed that. Afterwards I got this error:

make test
ruby test.rb
../tests/Matrix4.tests.rb:32: warning: default `to_a' will be obsolete
../tests/Bound.tests.rb:30: warning: default `to_a' will be obsolete
../tests/Require.tests.rb:27: warning: parenthesize argument(s) for future
version
Required 9 files.
test.rb:45:in `suite': undefined method `add' for
#<Test::Unit::TestSuite:0x404e0b84> (NoMethodError)
from test.rb:44:in `each_object'
from test.rb:44:in `suite'
from /usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:27:in
`initialize'
from test.rb:53:in `new'
from test.rb:53
make: *** [test] Error 1

(I'll ignore the to_a warnings, those tests work)
But the suite method add is missing, I replaced it with the << method in
test.rb:
ObjectSpace.each_object( Class ) {|klass|
suite << klass.suite if klass < Test::Unit::TestCase
}

Next my tests ran, without good results:

make test
ruby test.rb
../tests/Matrix4.tests.rb:32: warning: default `to_a' will be obsolete
../tests/Bound.tests.rb:30: warning: default `to_a' will be obsolete
../tests/Require.tests.rb:27: warning: parenthesize argument(s) for future
version
Required 9 files.
Loaded suite Math3d Test Suite
Started
EEE.EEEEEE....EEEEEEEEEEE.EEEEEEEEE.EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE.EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE.EEEEEEFFEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
Finished in 0.207462 seconds.

1) Error:
test_00_7_contains?(OrthoTestCase):
NoMethodError: undefined method `each' for nil:NilClass
./tests/Ortho.tests.rb:65:in `test_00_7_contains?'
./tests/m3dUnitTest.rb:63:in `run'

Somehow the setup methods don't work? It seems there is something wrong with
the testsuite, but I don't see what...

Bart
 
B

Bart Braem

Paul said:
But I ask you to consider this. From a user's perspective, the total
runtime is the total of the preparation time plus the time spent using the
library. I suspect that the total time for making this library work for
you will soon cross over a threshold beyond which it would have been
quicker and easier to write, test and use your own 3D vector routines,
composed in plain Ruby.

Another advantage to writing your own code -- oops, I mean your
own library -- is that the resulting library will be understood by you,
it will be composed in the very readable and transparent syntax for which
Ruby is justly famous, and you will be able to change it very quickly and
easily to meet new requirements.

In exchange, it will not be nearly as fast as a compiled, native-code
library would have been, if the library had ever been successfully
compiled and run.

I understand your arguments but I'm looking at this from different
perspectives.

As a programmer I do not mind fixing this to learn more about Ruby libraries
and have a better understanding on how to write and use them. I got this
one fixed (almost, see my most recent post) so I don't mind. Of course when
it would not have worked out soon enough I would have left it.

Another argument pro is that this library is tested. When writing this
myself I am bound to make errors. Here there are a number of tests so
that's less probable.

A last and most important argument is that I need the performance. I am
going to write large programs where lots of 3D calculations are necessary.
Then I need the C performance, but preferably hidden away in a nice Ruby
library.

(So my decision is to use the library, as I have it working.)

Regards,
Bart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top