I would like to know if I am correct with understanding the constructor argument as a Function<Point2D, Number> function
.
My function which I have used for 1D charts based on the applying the variables after every step on the x axis, but there is as a parametr Point2D
which contain 2 variables : x
and y
, if i am correct the x
varriable is step which increase "0.5" for every calculations after apply
the function of y.
Then what is the second parametr of generic type, the Number
?
How could I implement other functions, using the SurfacePlotMesh
class. Could someone explain me a little bit how it works ? Or link the documenations ( If it exist ) ?

- 44,311
- 7
- 104
- 132

- 1,366
- 3
- 17
- 44
1 Answers
If you have a look at the code for SurfacePlotMesh
in the FXyz library, you'll find createPlotMesh()
, a method that creates the mesh for the surface, based on two coordinates on a plane grid (x, y), taken from the Point2D
coordinates, and a function value (z), given by the function applied on that point.
If you have a look at the default parameters:
private static final Function<Point2D, Number> DEFAULT_FUNCTION =
p -> Math.sin(p.magnitude()) / p.magnitude();
private static final double DEFAULT_X_RANGE = 10; // -5 +5
private static final double DEFAULT_Y_RANGE = 10; // -5 +5
private static final int DEFAULT_X_DIVISIONS = 64;
private static final int DEFAULT_Y_DIVISIONS = 64;
private static final double DEFAULT_FUNCTION_SCALE = 1.0D;
what it means it that there will be a grid of 10x10 units, with 64x64 divisions. In each and every vertex (x,y) of the total 65x65 vertices, we will evaluate the function to get the value z = f(x, y), with a default scale of 1.
I.e., for the top left 2D point at (-5, -5) -> f(-5, -5) = 1.0025, so the 3D point for the mesh will be (-5, -5, 1.0025), and so on.
This picture shows a grid of 10x10 range with 20x20 divisions, and the mesh with a scale of 4 for that function.
You can change the function at any time, like:
- p -> p.getX()
- p -> p.getX() * p.getY()
- p -> Math.cos(p.getX()) * Math.sin(p.getY())
- ...
as well as the other parameters (range, divisions, scale).
For the moment there is no documentation, but the code is fully available.
Also there is a sampler to run most of the samples and modify the parameters to easily check the result without recompiling all over again here.
EDIT
Based on the OP comment, for a function where there is no y
dependency, a ribbon type of surface can be created by setting a very low value on y:
private void createSurface(double time) {
surface = new SurfacePlotMesh(
p-> Math.sqrt(Math.pow(Math.exp(-(Math.pow((p.getX() - time), 2))) *
(Math.cos((2 * Math.PI * (p.getX() - time)))), 2) +
Math.pow(Math.exp(-(Math.pow((p.getX() - time), 2))) *
(Math.sin((2 * Math.PI * (p.getX() - time)))), 2)),
10, 0.1, 64, 2, 2);
}
where the time
parameter will be set to a fixed value or in an animation.

- 44,311
- 7
- 104
- 132
-
How it would look for exmaple with this function 'x -> x = Math.sqrt(Math.pow(Math.exp(-(Math.pow((x - this.time), 2))) * (Math.cos((2 * Math.PI * (x - this.time)))), 2) + Math.pow(Math.exp(-(Math.pow((x - this.time), 2))) * (Math.sin((2 * Math.PI * (x - this.time)))), 2));' the result from this function will be y coordinate and x will be from -1 to 1 and it will be increase by 0.1, how could I code it using the constructor of `SurfacePlotMesh` ? – yerpy May 17 '16 at 19:08
-
1With a 1D function, at any given time, you'll get a curve, not a surface. If you use `SurfacePlotMesh` replace `x` with `p.getX()` and you'll get a constant value for any value of `y`, so you can narrow down the y range. – José Pereda May 17 '16 at 19:18
-
I've edited my answer with a possible solution to that case – José Pereda May 17 '16 at 19:37
-
p.getX() guessing is the default x from declared point2D from the FXyz library ? – yerpy May 17 '16 at 19:44
-
For Point2D we use `javafx.geometry.Point2D`, while for Point3D we have our `org.fxyz.geometry.Point3D`. – José Pereda May 17 '16 at 19:47
-
Also how I could get smooth animation which could show changes like "real curtain in the wind" and it all based on the time line with low increase of the time ? Then If i want to get surface what do i have to do with this pattern ? – yerpy May 17 '16 at 19:50
-
Then you need to have a look at the [cloth mesh](https://github.com/FXyz/FYzx/tree/master/src/cloth), preview [here](https://www.youtube.com/watch?v=Gaego44736k&feature=youtu.be&a) – José Pereda May 17 '16 at 19:57
-
It looks amazing! I'll take care of it tomorrow, have to finish stuff with that things first. Are there included Axes for the library ? – yerpy May 17 '16 at 20:21
-
1Yes, there are axes [here](https://github.com/Birdasaur/FXyz/blob/master/src/org/fxyz/utils/Axes.java) – José Pereda May 17 '16 at 20:23
-
How can I add the curve into those axes ? – yerpy May 17 '16 at 20:32
-
Try it for yourself, and post a new question if you find difficulties – José Pereda May 17 '16 at 20:35
-
OK! Thanks for everything! – yerpy May 17 '16 at 20:37