Be the first to rate this file! 8 Downloads (last 30 days) File Size: 2.04 KB File ID: #19515
image thumbnail

polyrevolve

by Kevin Moerman

 

09 Apr 2008 (Updated 14 Aug 2008)

'Copies' data points of a 2D polygon around an axis to obtain 3D data points of the revolved shape

| Watch this File

File Information
Description

[X,Y,Z]=polyrevolve(x,z,n)

This function revolves a 2D polygon around the Z-axis. It copies the 2D data points evenly around the axis and produces a 3D data set suitable for input to MESHGRID and GRIDDATA to create a 3D surface.
Useful to convert 2D axisymmetric data to 3D surfaces for presentation and or analysis.
The spacing from one revolved point to the next is defined by the parameter n. The required angular spacing (alpha) for each point is determined using the relationship n=2*r*sin(alpha).

%% EXAMPLE:
clear all; close all; clc;
x=0:0.2:2*pi;
z=sin(x+(pi/2));
revolve_res=0.2;
[X,Y,Z]=polyrevolve(x,z,revolve_res);
 
grid_res=0.05;
[XI,YI] = meshgrid(min(min(X)):grid_res:max(max(X)),min(min(Y)):grid_res:max(max(Y)));
ZI = griddata(X,Y,Z,XI,YI,'cubic');
figure; fig=gcf; clf(fig); units=get(fig,'units'); set(fig,'units','normalized','outerposition',[0 0 1 1]); set(fig,'units',units);
plot(x,z,'r-'); hold on; axis equal;
xlabel('x (mm)'); ylabel('z (mm)');
title('The polygon');
xlabel('x (mm)'); ylabel('z (mm)');
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;
title('Data "copied" around z-axis using POLYREVOLVE');
xlabel('x (mm)'); ylabel('y (mm)'); zlabel('z (mm)');
figure; fig=gcf; clf(fig); units=get(fig,'units'); set(fig,'units','normalized','outerposition',[0 0 1 1]); set(fig,'units',units);
surf(XI,YI,ZI,'EdgeColor','none'); hold on; axis equal;
shading interp; material shiny; lightangle(45,30);
title('Surface fit of the revolved data points');
xlabel('x (mm)'); ylabel('y (mm)'); zlabel('z (mm)');

Acknowledgements
This submission has inspired the following:
spheregrid
MATLAB release MATLAB 7.6 (R2008a)
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
07 May 2008

The point spacing or increment theta_inc initially depended on the radius from the origin. This has been changed to the distance from the revolution axis.

14 Aug 2008

Error related to point spacing fixed

Tag Activity for this File
Tag Applied By Date/Time
data exploration Kevin Moerman 22 Oct 2008 09:56:58
revolve Kevin Moerman 22 Oct 2008 09:56:58
polygon Kevin Moerman 22 Oct 2008 09:56:58
data points Kevin Moerman 22 Oct 2008 09:56:58
2d Kevin Moerman 22 Oct 2008 09:56:58
graphical data Kevin Moerman 22 Oct 2008 09:56:58
graphics Kevin Moerman 22 Oct 2008 09:56:58
polygon Patrick 24 Sep 2009 08:31:04
2d Ranja RABARIJOELINA 25 Mar 2010 06:18:57
data exploration Ranja RABARIJOELINA 25 Mar 2010 06:18:59

Contact us at files@mathworks.com