Ask Your Question

Best way to import Sage 3D functions to cubes in Unity3D?

asked 2016-11-10 23:01:26 +0200

remixie gravatar image

Hello everyone. I'm having a bit of trouble figuring out how to take a 3D function, say something like:

implicit_plot3d(sqrt(3*x^2+y^2)-z, (x, -30, 30), (y, -30,30), (z, -10,40))

and have it translated and rendered inside of a transparent cube in Unity3D.

Is there a way to do this? If so, how? I have done some investigation by myself and I know that there is a Python interpreter asset for Unity but would Sage be able to run off of the interpreter?

I'm just very confused.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2016-11-11 08:51:55 +0200

FrédéricC gravatar image

Did you look at the doc of save ?

sage: var('x,y,z')
sage: P=implicit_plot3d(sqrt(3*x^2+y^2)-z, (x, -30, 30), (y, -30,30), (z, -10,40))

This offers several formats, such as .x3d that could be possible inputs for other 3d software.

edit flag offensive delete link more

answered 2016-11-11 23:28:50 +0200

If you're looking for a WebGL-oriented approach, then use the json_repr of a 3D surface. This code

var('x y z')
p = implicit_plot3d(sqrt(3*x^2+y^2)-z, (x, -30, 30), (y, -30,30), (z, -10,40))

returns an array of vertices, faces and color as can be seen in this live example. The array can be saved to file using Python

f = open('data.json', 'w')

and imported into Unity. This will work for any surface composed of faces, but not for 3D lines and points.

One catch is that by default Sage returns quadrilateral faces instead of triangles. If Unity can't import quadrilateral faces you'll need to split the quads into triangles beforehand. That's pretty straightforward in either Python or JavaScript.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-11-10 22:58:52 +0200

Seen: 240 times

Last updated: Nov 11 '16