MATLAB Answers

0

how to plot multiple implicit quadratic surfaces at once ?

Asked by Itzik Ben Shabat on 11 Aug 2014
Latest activity Answered by Yu Jiang
on 11 Aug 2014
Hi,
so i wrote the following code to plot a single quadratic implicit surface based on the ezimplot3 function from matlab exchange.
In order to plot multiple surfaces i have to run this function in a loop which takes a lot of time.
Is there a way to do this using vectors and matrices ? (which i know is much faster).
I mean that here C would be a matrix of coefficient (each row representing a different quadratic) and Domain would also be a matrix (each row will contain the domain of the corresponding quadratic in C). i donw mind that step would remain constant for all surfaces.
function [ model_handle ] = PlotImplicitQuadratcSurface( C,Domain,step )
%PlotImplicitQuadratcSurface plots the implicit quadratic functions dfined
%by the parametes in C
%INPUT:
%C: 1x10 vector containing the quadratic coefficients
%Domain: 1x6 vector containing the limits in which to plot the quadratic
%OUTPUT:
%model_handle: a handle to the patch object
%initialize variables
color='r';
%code
xm= linspace(Domain(1),Domain(2),step);
ym = linspace(Domain(3),Domain(4),step);
zm = linspace(Domain(5),Domain(6),step);
[X,Y,Z] = meshgrid(xm,ym,zm);
fvalues=C(1)+C(2).*X+C(3).*Y+C(4).*Z+C(5).*X.^2+C(6).*Y.^2+C(7).*Z.^2+C(8).*X.*Y+C(9).*Y.*Z+C(10).*Z.*X;
model_handle = patch(isosurface(X,Y,Z,fvalues,0)); % "patch" handles the structure...
% sent by "isosurface"
isonormals(X,Y,Z,fvalues,model_handle)% Recalculating the isosurface normals based...
% on the volume data
set(model_handle,'FaceColor',color,'EdgeColor','none');
% Aditional graphic details:
alpha(0.7) % adjusting for some transparency
grid on;
view([1,1,1]);
axis equal;
camlight;
lighting gouraud
end

  0 Comments

Sign in to comment.

1 Answer

Answer by Yu Jiang
on 11 Aug 2014

Hi Itzik Ben Shabat
I agree that you could revise the function such that it takes input arguments C and D as matrices with multiple rows. However, you may still need to use a for loop inside the function because not everything here is vectorizable.
For example, the first two arguments in linspace must be scalars. Also, patch will return only one handle, not a vector of handles. isonormal cannot take 4-D matrices as its first three arguments.
Therefore, I think the idea of vectorization may not significantly reduce the execution time of the code. If you would like to find out more details regarding vectorization in MATLAB, please see the documentation via the following link
-Yu

  0 Comments

Sign in to comment.