| Description |
function [X,Y,Z]=spheregrid(xc,yc,zc,n,rc)
This function generates X,Y,Z coordinates of points inside a circle for the 2D case or inside a sphere for the 3D case with a radius of rc. The points are distrubuted according to n which is the spacing between points in radians.
x,y,z are the x,y,z coordinates of the desired centre point
n is the resolution of the rotation in radians
rc is the radius of the required circle/sphere
For the 2D case:
[X,Y]=spheregrid(x,y,z,revolve_res,r)
For the 3D case
[X,Y,Z]=spheregrid(xc,yc,zc,n,rc)
%EXAMPLE
clear all; close all; clc;
x=2; y=2; z=0; r=1; revolve_res=0.1;
%2D: points in a circle
[X,Y]=spheregrid(x,y,z,revolve_res,r);
figure; fig=gcf; clf(fig); units=get(fig,'units'); set(fig,'units','normalized','outerposition',[0 0 1 1]); set(fig,'units',units);
% subplot(1,2,1);
% plot(x,y,'ro'); hold on; axis equal;
% plot(X,Y,'k.'); hold on; axis equal;
% xlabel('x'); ylabel('y');
% title('2D: points in a circle');
% %3D: points in a sphere
% [X,Y,Z]=spheregrid(x,y,z,revolve_res,r);
% plot3(x,y,z,'ro'); hold on; axis equal;
% [X_sp,Y_sp,Z_sp] = sphere(100); X_sp=(r*X_sp)+x; Y_sp=(r*Y_sp)+y; Z_sp=(r*Z_sp)+z;
% subplot(1,2,2);
% figure; fig=gcf; clf(fig); units=get(fig,'units'); set(fig,'units','normalized','outerposition',[0 0 1 1]); set(fig,'units',units);
% plot3(X,Y,Z,'k.'); hold on; axis equal; grid on;
% surf(X_sp,Y_sp,Z_sp,'EdgeColor','none','FaceColor','g','FaceAlpha',0.5);
% axis equal;hold on;lightangle(80, -40);lightangle(-90, 60);
% title('3D: points in a sphere');
%
% Kevin Mattheus Moerman
% kevinmoerman@hotmail.com
% 25/05/2008 |