Wednesday, August 14, 2013

Matlab: plot 3D object defined by function g=f(x,y,z)

Usually a 3D object can be described by function of x,y, and z. For example, a 3D sphere centered at (0,0,0) can be described as:
x^2+y^2+z^2=r^2
where the r s the radius of the sphere.
How to plot this object in matlab? Here's my solution:

close all;
clc;
clear;

[x, y,z]=meshgrid(-3:0.1:3, -3:0.1:3,-3:0.1:3);
v1=x.^2+y.^2+z.^2; % create the 1st object
r1=2;% set radius
p1=patch(isosurface(x,y,z,v1,r1));
set(p1, 'FaceColor','r')
hold on

v2=(x-1).^2+(y-1).^2+(z-1).^2;% create the 2nd object
r2=3;
p2=patch(isosurface(x,y,z,v2,r2));
set(p2,'FaceColor','b')
view(3)% set to 3D view 




x^2+y^2+z^2=r^2
 x^2+y^2+z^2=r^2


(x+2-y^2)^2+y^2+z^2=6

(x+2-y^2+z^3)^2+y^2+z^2=6

1 comment:

  1. You can get some latest computer tips, blogging tips and internet tips in the blog TechnTechie.

    ReplyDelete

Any comments?

my-alpine and docker-compose.yml

 ``` version: '1' services:     man:       build: .       image: my-alpine:latest   ```  Dockerfile: ``` FROM alpine:latest ENV PYTH...