Plot 3D Function: Point Where f=1, No Point Where f=0

In summary: If your function has values of approximately 0 or 1 ( i.e. f= -0.1 to 0.1, and f=0.9 to 1.1) how would you achieve this...I'm not sure what you are asking.
  • #1
Ben Wilson
90
16
I had a function of 3 variables f'(kx,ky,kz)

and did an ifft

f = ifft(f')

and now i have a function where inside a small polygon the function f = 1, and outside f=0, within a cube space of length L.

how do i plot a scatter graph for this function where there is a point when f =1, and no point when f=0?
 
Physics news on Phys.org
  • #2
You would have to consider if a scatter graph is the best way to represent this function.
How you plot the graph depends on what you want to be able to do with it.
You could see what is possible by plotting slices through the data by more intuitive approaches.
Usually you would color-code the dots for magnitude and the graph would look like an array.

Note: you cannot have 3D polygon... by definition a polygon is a 2D object.
So I think you would benefit from a more careful description.
 
  • #3
Simon Bridge said:
You would have to consider if a scatter graph is the best way to represent this function.
How you plot the graph depends on what you want to be able to do with it.
You could see what is possible by plotting slices through the data by more intuitive approaches.
Usually you would color-code the dots for magnitude and the graph would look like an array.

Note: you cannot have 3D polygon... by definition a polygon is a 2D object.
So I think you would benefit from a more careful description.
a polyhedron sorry.

what i want to be able to do is see the polyhedron.
 
  • #4
Can you show some more code?

I want to recommend that you use alphaShape to generate the polyhedron, but it sounds like you have 4-D data since the function values depend on x,y,z.

http://www.mathworks.com/help/matlab/ref/alphashape.html

If your data is really 4-D, then you could use delaunayn to generate an N-D triangulation. But you still wouldn't be able to plot the output unless you take 3-D slices.
 
  • #5
kreil said:
Can you show some more code?

I want to recommend that you use alphaShape to generate the polyhedron, but it sounds like you have 4-D data since the function values depend on x,y,z.

http://www.mathworks.com/help/matlab/ref/alphashape.html

If your data is really 4-D, then you could use delaunayn to generate an N-D triangulation. But you still wouldn't be able to plot the output unless you take 3-D slices.
i'm not trying to "generate" a polyhedron as such, I have a function F of 3d space (x,y,z). At each point the function is valued as either zero or one. I want to plot a marker on a 3d graph wherever F=1 in the x-y-z space.
 
  • #6
This is part of my code, in the code there is a function in inverse space (chi_wedge), and I want plot its IFT in real space by plotting a data point wherever the function takes the value 1.No_x = 100;
i_x = 1:No_x;
dx = L/(No_x - 1);
No_k0 = 100;

%real space
r_x = linspace(-L/2, L/2, No_x);
r_y = linspace(-L/2, L/2, No_x);
r_z = linspace(-L/2, L/2, No_x);
[r_x,r_y,r_z] = meshgrid(r_x,r_y,r_z);

%inverse space
k_x = linspace(-No_k0*2*pi/L,No_k0*2*pi/L,(2*No_k0)+1);
k_y = linspace(-No_k0*2*pi/L,No_k0*2*pi/L,(2*No_k0)+1);
k_z = linspace(-No_k0*2*pi/L,No_k0*2*pi/L,(2*No_k0)+1);
[k_x,k_y,k_z] = meshgrid(k_x,k_y,k_z);

%%%%

f = ifft(chi_wedge);
 
  • #7
Hmm. It sounds like you want to generate a 3-D grid of sample points over some range -L/2 to L/2:

Code:
L= 10;
[x,y,z] = meshgrid(-L/2:L/100:L/2);
plot3(x(:), y(:), z(:), '.') %plot the entire grid as blue points

Then you want to filter these points according to whether f=1:
Code:
idx = find(f) % finds linear indices for all places where f is nonzero
x_new = x(idx); %filter x,y,z points based on where f is nonzero
y_new = y(idx);
z_new = z(idx);

% Plot only the points from the grid where f=1
plot3(x_new(:), y_new(:), z_new(:), 'r*')

Is this in the ballpark of what you're looking for?
 
  • Like
Likes Ben Wilson
  • #8
kreil said:
Hmm. It sounds like you want to generate a 3-D grid of sample points over some range -L/2 to L/2:

Code:
L= 10;
[x,y,z] = meshgrid(-L/2:L/100:L/2);
plot3(x(:), y(:), z(:), '.') %plot the entire grid as blue points

Then you want to filter these points according to whether f=1:
Code:
idx = find(f) % finds linear indices for all places where f is nonzero
x_new = x(idx); %filter x,y,z points based on where f is nonzero
y_new = y(idx);
z_new = z(idx);

% Plot only the points from the grid where f=1
plot3(x_new(:), y_new(:), z_new(:), 'r*')

Is this in the ballpark of what you're looking for?

yes that is what I'm looking for thank you.

If my function has values of approximately 0 or 1 ( i.e. f= -0.1 to 0.1, and f=0.9 to 1.1) how would I achieve this separation?
 
  • #9
Ben Wilson said:
If my function has values of approximately 0 or 1 ( i.e. f= -0.1 to 0.1, and f=0.9 to 1.1) how would I achieve this separation?

Since the FIND function only locates nonzeros, and you don't want to do exact comparisons with floating-point numbers, you should just use a rounding function on the function values before you pass them to find. This ensures that the values close to zero are exactly zero for the purposes of FIND.

It looks like you just need to use round(f) to round the values of f to the nearest integer. But other options are:

  • ceil rounds to the nearest integer towards +Inf.
  • floor rounds to the nearest integer towards -Inf.
  • fix rounds to the nearest integer towards zero.
 
  • Like
Likes Ben Wilson
  • #10
kreil said:
Since the FIND function only locates nonzeros, and you don't want to do exact comparisons with floating-point numbers, you should just use a rounding function on the function values before you pass them to find. This ensures that the values close to zero are exactly zero for the purposes of FIND.

It looks like you just need to use round(f) to round the values of f to the nearest integer. But other options are:

  • ceil rounds to the nearest integer towards +Inf.
  • floor rounds to the nearest integer towards -Inf.
  • fix rounds to the nearest integer towards zero.
thank you so much, you have been an amazing help
 

Related to Plot 3D Function: Point Where f=1, No Point Where f=0

1. What does it mean for a plot to have a point where f=1?

When a plot has a point where f=1, it means that the function being plotted has a value of 1 at that specific point. This point can be seen as a peak or a high point on the plot.

2. Can a plot have multiple points where f=1?

Yes, a plot can have multiple points where f=1. This means that the function being plotted has multiple peaks or high points.

3. Why is it important to know where f=1 on a plot?

Knowing where f=1 on a plot can help in understanding the behavior of the function and identifying any critical points. It can also provide information about the maximum value of the function.

4. What does it mean for there to be no point where f=0 on a plot?

If there is no point where f=0 on a plot, it means that the function being plotted never crosses the x-axis. This can indicate that the function has a constant value or that it approaches but never reaches 0.

5. How can I determine the point where f=1 on a 3D plot?

To determine the point where f=1 on a 3D plot, you can use the coordinates given on the plot or use mathematical techniques such as finding the derivative and setting it equal to 0.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
Back
Top