在 JavaFX 中绘制 3d 曲面

编程入门 行业动态 更新时间:2024-10-25 10:29:55
本文介绍了在 JavaFX 中绘制 3d 曲面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何使用数学方程式在 JavaFX 中绘制 3d 图形,基本上是2个变量函数,例如:z=2xy和其他3D图形?有什么办法可以在 JavaFX 中做到这一点,或者我需要另一个 Java 库.

解决方案

正如@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 曲面

本文发布于:2023-07-17 17:09:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1135392.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:曲面   JavaFX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!