plot - Visualize conic with Matlab or Octave -


i visualize conics matlab or octave. (general) conic given equation 0 = ax² + bxy + cy² +dxz +eyz+f*z² point p=(x,y,z). how can plot matlab or octave if know parameters a,b,c,d,e , f? or respectively, how can find points satisfy equation?

since asking conics, understand referring 2d contours of general conic equation. cover how visualize equation in other different ways.

for following examples, have set conic constants obtain hiperboloid.

my code written in matlab syntax. if using octave, might differ slightly.

visualizing 2d conics contour

i have isolated z in terms of x , y, general conic equation:

z = (1/2)*(-d*x-e*y±sqrt(-4*a*f*x.^2-4*b*f*x.*y-4*c*f*y.^2+d^2*x.^2+2*d*e*x.*y+e^2*y.^2))/f; 

since z piecewise function due (± sqrt), need make sure plot both hemispheres. designate z1 +sqrt, , z2 -sqrt.

finally, plot contours z1 , z2 yield set of conics in 2d. conics circles of different radius.

code:

clear all; clc;  % conic constants. = 1; b = 0; c = 1; d = 0; e = 0; f = -1;  % value x , y domain. v = 10;  % domain x , y. x = linspace(-v,v); y = linspace(-v,v);  % generate 2d mesh x , y. [x,y] = meshgrid(x,y);  % isolate z in terms of x , y. z1 = (1/2)*(-d*x-e*y+sqrt(-4*a*f*x.^2-4*b*f*x.*y-4*c*f*y.^2+d^2*x.^2+2*d*e*x.*y+e^2*y.^2))/f; z2 = (1/2)*(-d*x-e*y-sqrt(-4*a*f*x.^2-4*b*f*x.*y-4*c*f*y.^2+d^2*x.^2+2*d*e*x.*y+e^2*y.^2))/f;  % find complex entries in z. = find(real(z1)~=z1); j = find(real(z2)~=z2);  % replace complex entries nan. z1(i) = nan; z2(j) = nan;  figure;  subplot(1,2,1); % draw lower hemisphere. contour(x,y,z1,'showtext','on');  % adjust figure properties. title('2d conics: lower hemishphere'); xlabel('x-axis'); ylabel('y-axis'); axis equal; grid on; box on; axis([-10 10 -10 10]);  subplot(1,2,2); % draw upper hemisphere. contour(x,y,z2,'showtext','on'); hold off;  % adjust figure properties. title('2d conics: upper hemishphere'); xlabel('x-axis'); ylabel('y-axis'); axis equal; grid on; box on; axis([-10 10 -10 10]); 

output:

2d conics

visualizing 3d conics contour3

same on previous example, plot set of conics in 3d.

code:

clear all; clc;  % conic constants. = 1; b = 0; c = 1; d = 0; e = 0; f = -1;  % value x , y domain. v = 10;  % domain x , y. x = linspace(-v,v); y = linspace(-v,v);  % generate 2d mesh x , y. [x,y] = meshgrid(x,y);  % isolate z in terms of x , y. z1 = (1/2)*(-d*x-e*y+sqrt(-4*a*f*x.^2-4*b*f*x.*y-4*c*f*y.^2+d^2*x.^2+2*d*e*x.*y+e^2*y.^2))/f; z2 = (1/2)*(-d*x-e*y-sqrt(-4*a*f*x.^2-4*b*f*x.*y-4*c*f*y.^2+d^2*x.^2+2*d*e*x.*y+e^2*y.^2))/f;  % find complex entries in z. = find(real(z1)~=z1); j = find(real(z2)~=z2);  % replace complex entries nan. z1(i) = nan; z2(j) = nan;  % lower hemisphere. draw 20 conics. contour3(x,y,z1,20); hold on; % upper hemisphere. draw 20 conics. contour3(x,y,z2,20); hold off;  % adjust figure properties. title('3d conics'); xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis'); axis equal; grid on; box on; axis([-10 10 -10 10 -10 10]); 

output:

3d conics

visualizing quadrics isosurface

i have isolated f in terms of x, y , z, general conic equation, , renamed f_eq:

f_eq = -(a*x.^2+b*x.*y+c*y.^2+d*x.*z+e*y.*z)./z.^2; 

finally, obtain set of points satisfy equation f_eq = f, in fact isosurface yields quadric; in example hiperboloid.

code:

clear all; clc;  % conic constants. = 1; b = 0; c = 1; d = 0; e = 0; f = -1;  % value x, y , z domain. v = 10;  % domain x ,y , z. x = linspace(-v,v); y = linspace(-v,v); z = linspace(-v,v);  % generate 3d mesh x, y , z. [x,y,z] = meshgrid(x,y,z);  % evaluate function (3d volume of data). f_eq = -(a*x.^2+b*x.*y+c*y.^2+d*x.*z+e*y.*z)./z.^2;  % draw surface matches f_eq = f. p = patch(isosurface(x,y,z,f_eq,f)); isonormals(x,y,z,f_eq,p) p.facecolor = 'red'; p.edgecolor = 'none';  % adjust figure properties. title('quadric'); xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis'); axis equal; grid on; box on; axis([-10 10 -10 10 -10 10]); camlight left; lighting phong; 

output:

hiperboloid of 2 sheets


Comments

Popular posts from this blog

php - Passing multiple values in a url using checkbox -

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -