看看FXyz library。它是開源的,你可以從代碼中學習。
對於紋理,看看這個post。
FXyz有SurfacePlotMesh
的類,它正是你想要的:情節基於函數g = f(x,y)
,通過使用Function<Point2D, Number> function
參數3D表面。
它還包含紋理,因此您可以根據Function<Point3D, Number> density
包含密度圖。每個值都映射到一種顏色。
檢查此項測試Function2DPlotTest
here。
有了這段代碼可以繪製一個函數:
@Override
public void start(Stage primaryStage) {
PerspectiveCamera camera = new PerspectiveCamera(true);
camera.setTranslateZ(-30);
SurfacePlotMesh surface = new SurfacePlotMesh(
p-> Math.sin(p.magnitude() + 1e-10)/(p.magnitude() + 1e-10),
20, 20, 100, 100, 4);
surface.setCullFace(CullFace.NONE);
surface.setTextureModeVertices3D(1530, p -> p.magnitude());
surface.getTransforms().addAll(new Rotate(200, Rotate.X_AXIS), new Rotate(-20, Rotate.Y_AXIS));
final Group group = new Group(surface);
Scene scene = new Scene(group, 600, 400, true, SceneAntialiasing.BALANCED);
scene.setCamera(camera);
primaryStage.setScene(scene);
primaryStage.show();
}
如果你添加一個密度圖:
surface.setTextureModeVertices3D(1530, p -> p.magnitude());
你會得到這樣的:
現在如果你想表面的動畫,你只需要創建一個:
private SurfacePlotMesh surface;
private long lastEffect;
@Override
public void start(Stage primaryStage) {
PerspectiveCamera camera = new PerspectiveCamera(true);
camera.setTranslateZ(-30);
surface = new SurfacePlotMesh(
p-> Math.sin(p.magnitude() + 1e-10)/(p.magnitude() + 1e-10),
20, 20, 100, 100, 4);
surface.setCullFace(CullFace.NONE);
surface.setTextureModeVertices3D(1530, p -> p.magnitude());
surface.getTransforms().addAll(new Rotate(200, Rotate.X_AXIS), new Rotate(-20, Rotate.Y_AXIS));
final Group group = new Group(surface);
Scene scene = new Scene(group, 600, 400, true, SceneAntialiasing.BALANCED);
scene.setCamera(camera);
primaryStage.setScene(scene);
primaryStage.show();
lastEffect = System.nanoTime();
AtomicInteger count=new AtomicInteger();
AnimationTimer timerEffect = new AnimationTimer() {
@Override
public void handle(long now) {
if (now > lastEffect + 1_000_000_000l) {
double t = (count.get() % 5 + 1);
surface.setFunction2D(p -> Math.sin(t * p.magnitude() + 1e-10)/(t * p.magnitude() + 1e-10));
count.getAndIncrement();
lastEffect = now;
}
}
};
timerEffect.start();
}
,你會得到你的面動畫:
這是關於動畫「c瞬間「表面或關於改變表面? – fabian
它會根據時間更改新數據表面 – yerpy