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

Click For Summary

Discussion Overview

The discussion revolves around plotting a 3D function defined in a cubic space, where the function takes values of either 1 or 0. Participants explore methods for visualizing this function, particularly focusing on how to represent points where the function equals 1 and ensuring no points are plotted where the function equals 0.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes a function of three variables and the results of applying an inverse Fourier transform, leading to a function that is 1 inside a polygon and 0 outside.
  • Some participants question the appropriateness of using a scatter graph to represent the function and suggest alternative visualization methods, such as plotting slices or using color-coding.
  • There is a clarification that a polygon is a 2D object, and one participant corrects this to refer to a polyhedron instead.
  • Another participant suggests using alphaShape to generate a polyhedron from the data, while also noting the challenge of plotting 4-D data in a 3-D space.
  • One participant expresses a desire to plot markers in 3D space wherever the function equals 1, rather than generating a polyhedron.
  • Participants discuss generating a 3-D grid of sample points and filtering these points based on the function values to plot only those where the function equals 1.
  • There is a suggestion to use rounding functions to handle floating-point comparisons when determining where the function is approximately 0 or 1.

Areas of Agreement / Disagreement

Participants express varying opinions on the best method to visualize the function, with some advocating for scatter plots and others suggesting alternative approaches. There is no consensus on a single method, and the discussion remains open to different interpretations and techniques.

Contextual Notes

Participants note the limitations of plotting techniques in relation to the dimensionality of the data and the challenges of visualizing functions with floating-point values. The discussion highlights the need for careful consideration of definitions and representation methods.

Ben Wilson
Messages
90
Reaction score
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
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.
 
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.
 
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.
 
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.
 
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);
 
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   Reactions: Ben Wilson
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?
 
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   Reactions: 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
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K