Be the first to rate this file! 11 Downloads (last 30 days) File Size: 2.05 KB File ID: #20049
image thumbnail

spheregrid

by Kevin Moerman

 

25 May 2008 (Updated 05 May 2009)

Generates points inside a circle/sphere around a given centre point

| Watch this File

File Information
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

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
polyrevolve

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Updates
05 May 2009

Fixed centre offset for 3D case

Tag Activity for this File
Tag Applied By Date/Time
data exploration Kevin Moerman 22 Oct 2008 10:03:29
circle Kevin Moerman 22 Oct 2008 10:03:29
sphere Kevin Moerman 22 Oct 2008 10:03:29
cloud Kevin Moerman 22 Oct 2008 10:03:29
monte carlo Kevin Moerman 22 Oct 2008 10:03:29
points Kevin Moerman 22 Oct 2008 10:03:29
sphere Eric Diaz 15 Oct 2009 22:11:39
grid Eric Diaz 15 Oct 2009 22:11:49

Contact us at files@mathworks.com