在JavaFX中绘制3d表面 [英] Drawing 3d surfaces in JavaFX
问题描述
如何使用数学方程在JavaFX中绘制3d图形,
基本上是2个变量函数,例如: z = 2xy
和其他3D数字?
有没有办法在JavaFX中执行此操作,或者我是否需要另一个Java库。
As @Roland指出,JavaFX 3D API不包括基本元素,如
triangleMesh.getFaces()。setAll(0,0,20,0,21,0,...) ;
你将拥有你的网格,准备在场景中渲染。
第三方库
您可以查看
其他3D形状,查看库中其余3D复杂形状。
您可以查看 VRL Studio ,其中包括一个出色的3D功能绘图仪。
How to draw 3d graphs in JavaFX using a mathematical equation,
basically 2 variable functions, for example: z=2xy
and other 3D figures?
Is there any way to do it in JavaFX or do I need another Java library for that.
As @Roland points out, JavaFX 3D API doesn't include other than the basic elements, like TriangleMesh
, which you can use to create complex shapes, like 3D graphs.
In fact, plotting 2D functions f=f(x,y)
is be a very good use case for understanding how TriangleMesh
works.
Basically you will need:
A function
The function can be expressed using built-in Function
functional interface:
Function<Point2D,Number> function2D;
so for any pair of coordinates (x,y) it will return a value:
double value = function2D.apply(new Point2D(x,y)).doubleValue();
Grid or range of coordinates
If you think of a rectangular grid and a given number of the divisions, you will have a way to get all the plotting (x,y)
points, and with the function, you will have the third coordinate z
to generate the 3D points required for the mesh.
TriangleMesh triangleMesh = new TriangleMesh();
triangleMesh.getPoints().setAll(x0,y0,z0, x1,y1,z1, ...);
You will need to provide the texture coordinates if you want to have an image or a density map as a texture, or just an empty set of coordinates for now:
triangleMesh.getTexCoords().setAll(0,0);
Finally, you need to provide the faces, which are triangles. You just need to get the indices of the vertices for every triangle in your grid, like in this sample, using 0 for the texture indices in this case:
triangleMesh.getFaces().setAll(0,0,20,0,21,0,...);
And you will have your mesh, ready to be rendered in a scene.
Third party libraries
You can have a look at FXyz library, where you will find SurfacePlotMesh
, that will do exactly as described above, including texture coordinates. The FXyz Sampler is an application to visualize most of the possibilities on this library. This is a sample of a plotted function:
For other 3D shapes, have a look to the rest of the 3D complex shapes in the library.
And you can have a look to VRL Studio, which includes a great 3D function plotter, among other things.
这篇关于在JavaFX中绘制3d表面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!