Suppose you have f(x)=x-floor(x).
By this, you can generate the grooves by gluing the top side and the
bottom side together and then squeezing the left to zero -- now you
have a conical helix: the line spins around the cone until it hits the
bottom. You already have one form of the equations for the conical
helix namely x=a*cos(a); y=a*sin(a); z=a. Now like
here:
How can you project the conical helix on the cone in Matlab?
I'd approach your problem without using plot3, instead I'd use meshgrid and sinc. Note that sinc is a matlab built in functions that just do sin(x)./x, for example:
So in 1-D, if I understand you correctly you want to "project" sinc(x) on sqrt(x.^2). The problem with your question is that you mention projection with the dot product, but a dot product reduces the dimensionality, so a dot product of two vectors gives a scalar, and of two 2D surfaces - a vector, so I don't understand what you mean. From the 2-D plot you added I interpreted the question as to "dress" one function with the other, like in addition...
Here's the implementation:
N=64;
[x y]=meshgrid(linspace(-3*pi,3*pi,N),linspace(-3*pi,3*pi,N));
t=sqrt(x.^2+y.^2);
f=t+2*sinc(t);
subplot(1,2,1)
mesh(x,y,f) ; axis vis3d
subplot(1,2,2)
mesh(x,y,f)
view(0,0) ; axis square
colormap bone
The factor 2 in the sinc was placed for better visualization of the fluctuations of the sinc.
Related
I have used MATLAB to draw the following gain function of an antenna array, the code was as follows,
Nt=8;
deltat=1;
Lt=8;
omegat=-2:0.01:2;
for j=1:length(omegat)
gainfunction(j)= (1/Nt) * exp(i*pi*deltat* omegat(j)* (Nt-1)) * (sin(pi*Lt*omegat(j))/sin(pi*Lt*omegat(j)*Nt^-1));
end
plot(omegat,abs(gainfunction))
title( 'Radiation Pattern Cartesian Plot','linewidth',30)
grid on
ylabel('|f(\Omega_r)|','linewidth',25)
xlabel('\Omega_r','linewidth',15)
The image below is a radiation pattern of an antenna, i.e it shows the gain function denoted by |f(\Omega)| as function of $\Omega$ from -2 to 2.
My question is I would like to plot the following in polar coordinates to see how the main lobe is in degrees.
Any thoughts on how I can continue to the polar plot using MATLAB ?
polar (omegat*pi/2, abs(gainfunction));
I scaled omegat by pi/2 because I'm not sure what your convention here is. I'm assuming omegat must range from -pi to +pi and hence, I've scaled it by pi/2. Modify the scaling as you see fit.
Also, don't use i or j as loop counters in matlab. They're used in many places as iota or the sq root of minus one.
I want to plot an inequality in 3d using surf. My condition is
0<=x<=1
0<=y<=1
0<=z<=x/(1+y)
I can create a surface plot using the following commands
[x y]=meshgrid(0:0.01:1);
z=x./(1+y);
surf(x,y,z);
This plot gives me regions where z=x/(1+y) but I am interested in regions where 0<=z<=x/(1+y) over all values of x and y. However, I am unable to plot/color the region explicitly. Can you please help.
A similar question has been asked but there was no acceptable answer and my question is also different.
Using isosurface you can show the boundary. There are two options, first create the points
[X,Y,Z]=meshgrid(0:.01:1);
then plot the boundaries in the z-direction (i.e. Z=0 and Z=X./(1+Y))
isosurface(X,Y,Z,Z.*(X./(1+Y)-Z),0)
or plot all the boundaries (including X=0, X=1, Y=0 and Y=1)
isosurface(X,Y,Z,Z.*(X./(1+Y)-Z).*X.*(X-1).*Y.*(Y-1),0)
All you have to do is come up with a function that is constant on any boundary, its value inside or outside is irrelevant as long as it is not zero.
I have written an equation of cylinder in matlab as follows
z=0;
r=1/33;
a=1/2+1/4-1/8-1/16;
b=1/2+1/4-1/8-1/16;
if (x-a).^2+(y-b).^2<=r^2
z=1;
end
N=1-t(any number)
now I want to move it along x-axis with interval of time as above. I want to move it along x-axis
How can I do it?
Your equation (x-a).^2+(y-b).^2<=r^2 means that the cylinder's center is at [a, b]. Moving it along the x-axis by an amount da means increasing a to a+da, so that the new center moves to [a+da, b].
Just as a word of advice -- there is also the Matlab command [x,y,z] = cylinder. Type help cylinder for more info.
And for completeness and rigor -- your equation is not that of a cylinder, it is the equation of a plane (z=0) with a solid circular protrusion of height 1 and radius 1/33 centered at [a,b]. A "solid cylinder" like the one you've defined is best referred to as a "rod", whereas a mathematical "cylinder" is only the outer surface ("the collection of all points equidistant to a line segment"). Very often cylinders are defined through a set of parametric equations, so what are your reasons for this particular style of defining the rod?
I have a 3D data set of a surface that is not a function graph. The data is just a bunch of points in 3D, and the only thing I could think of was to try scatter3 in Matlab. Surf will not work since the surface is not a function graph.
Using scatter3 gave a not so ideal result since there is no perspective/shading of any sort.
Any thoughts? It does not have to be Matlab, but that is my go-to source for plotting.
To get an idea of the type of surface I have, consider the four images:
The first is a 3D contour plot, the second is a slice in a plane {z = 1.8} of the contour. My goal is to pick up all the red areas. I have a method to do this for each slice {z = k}. This is the 3rd plot, and I like what I see here a lot.
Iterating this over z give will give a surface, which is the 4th plot, which is a bit noisy (though I have ideas to reduce the noise...). If I plot just the black surface using scatter3 without the contour all I get is a black indistinguishable blob, but for every slice I get a smooth curve, and I have noticed that the curves vary pretty smoothly when I adjust z.
Some fine-tuning will give a much better 4th plot, but still, even if I get the 4th plot to have no noise at all, the result using scatter3 will be a black incomprehensible blob when plotted alone and not on top of the 3D contour. I would like to get a nice picture of the full surface that is not plotted on top of the 3D contour plot
In fact, just to compare and show how bad scatter3 is for surfaces, even if you had exact points on a sphere and used scatter3 the result would be a black blob, and wouldn't even look like a sphere
Can POV-Ray handle this? I've never used it...
If you have a triangulation of your points, you could consider using the trisurf function. I have used that before to generate closed surfaces that have no boundary (such as polyhedra and spheres). The downside is that you have to generate a triangulation of your points. This may not be ideal to your needs but it definitely an option.
EDIT: As #High Performance Mark suggests, you could try using delaunay to generate a triangulation in Matlab
just wanted to follow up on this question. A quick nice way to do this in Matlab is the following:
Consider the function d(x, y, z) defined as the minimum distance from (x, y, z) to your data set. Make sure d(x, y, z) is defined on some grid that contains the data set you're trying to plot.
Then use isosurface to plot a (some) countour(s) of d(x, y, z). For me plotting the contour 0.1 of d(x, y ,z) was enough: Matlab will plot a nice looking surface of all points within a distance 0.1 of the data set with good lighting and all.
In povray, a blob object could be used to display a very dense collection of points, if you make them centers of spheres.
http://www.povray.org/documentation/view/3.6.1/71/
If you want to be able to make slices of "space" and have them colored as per your data, then maybe the object pattern (based on a #declared blob object) might do the trick.
Povray also has a way to work with df3 files, which I've never worked with, but this user appears to have done something similar to your visualization.
http://paulbourke.net/miscellaneous/df3/
I have a formula that depends on theta and phi (spherical coordinates 0<=theta<=2*pi and 0<=phi<=pi). By inserting each engle, I obtained a quantity. Now I have a set of data for different angles and I need to plot the surface. My data is a 180*360 matrix, so I am not sure if I can use SURF or MESH or PLOT3. The figure should be a surface that include all data and the axes should be in terms of the quantity, not the quantity versus the angles. How can I plot such a surface?
I see no reason why you cannot use mesh or surf to plot such data. Another option I tend to use is that of density plots. You basically display the dependent variable (quantity) as an image and include the independent variables (angles) along the axis, much like you would with the aforementioned 3D plotting functions. This can be done with imagesc.
Typically you would want your axes to be the dependent variables. Could you elaborate more on this point?
If I understand you correctly you have calculated a function f(theta,phi) and now you want to plot the surface containing all the points with the polar coordinated (r,theta,phi) where r=f(theta,phi).
If this is what you want to do, the 2D version of such a plot is included in MATLAB under the name polar. Unfortunately, as you pointed out, polar3 on MatlabCentral is not the generalization you are looking for.
I have been able to plot a sphere with the following code, using constant r=1. You can give it a try with your function:
phi1=0:1/(3*pi):pi; %# this would be your 180 points
theta1=-pi:1/(3*pi):pi; % your 360 points
r=ones(numel(theta1),numel(phi1));
[phi,theta]=meshgrid(phi1,theta1);
x=r.*sin(theta).*cos(phi);
y=r.*sin(theta).*sin(phi);
z=r.*cos(theta);
tri=delaunay(x(:),y(:),z(:));
trisurf(tri,x,y,z);
From my tests it seems that delaunay also includes a lot of triangles which go through the volume of my sphere, so it seems this is not optimal. So maybe you can have a look at fill3 and construct the triangles it draws itself: as a first approximation, you could have the points [x(n,m) x(n+1,m) x(n,m+1)] combined into one triangle, and [x(n+1,m) x(n+1,m+1) x(n+1,m+1)] into another...?