How do define points as spheres in MATLAB
October 30, 2007 2:00 PM   Subscribe

In MATLAB, how do you represent moving objects not as points in 3d space but as spheres with a certain radius?

I am working in MATLAB to model spheres that need to touch each other in a continuous space. At the moment they are defined by x, y, and z coordinates and a certain vector velocity and are represented by points. I want them to be a 3d shape so that their surfaces can meet. I have been attempting to do this by setting the "markersize," however I cannot seem to figure out the algorithm that MATLAB uses to relate the arbitrary number for markersize and it's actual radius as compared to it's axes. Does anyone have suggestions for how to use Markersize and know it's actual radius or another method of representing a point as a sphere? Is my only option to define my own sphere at that point?
posted by kaozity to Computers & Internet (6 answers total) 1 user marked this as a favorite
 
You're making a plot, here? Or a drawing of some sort? 'MarkerSize' is for the size of markers on plots, in units of points.

If you just want a computational model, why not just give each object a radius r and if r1+r2 = sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2), objects 1 and 2 are touching?
posted by mr_roboto at 2:15 PM on October 30, 2007


You're not even trying.
posted by jeffamaphone at 2:16 PM on October 30, 2007


The sphere function is what you're looking for - there's comprehensive documentation on it in MATLAB's help feature. As far as I know, the markers are rendered from ASCII characters, and are not as 3D as you wish them to be.

I really do think making your own sphere is the only suggestion. Each sphere will be created as a new plot; add the coordinates of the desired location to the XYZ vectors of the sphere to shift it.
posted by kureshii at 4:35 PM on October 30, 2007


I understand your frustration (and your question). Yes, you want to write yourself a function that will do what kureshil described automatically and call it for each sphere you'd like to plot.

Let us know if it isn't clear how to write the function.
posted by onalark at 7:14 PM on October 30, 2007


In response to the Markersize question: from the help documentation, the scalar value is specified in points, 1 pt = 1/72 inch, though I'm not quite sure how differences between the various marker shapes are determined.

If you need it in terms of the axis scale, I guess you could do a get('XLim') or YLim, then normalise it and multiply it by the image size you hope to achieve to get your arbitrary markersize, or by using a similar algorithm. Though I still think doing a recurring sphere plot would be much simpler =)
posted by kureshii at 1:31 AM on October 31, 2007


I had some free time today and I scratched up a quick function to do this. I've commented out the function header but if you've worked with m-files before it should be fairly obvious how to turn the following code into a function (let us know if it isn't :)

Good luck!


%function plotSpheres(spheresX, spheresY, spheresZ, spheresRadius)

spheresX = [0 0 0 0 2 2 2 2];
spheresY = [0 0 2 2 0 0 2 2];
spheresZ = [0 2 0 2 0 2 0 2];
spheresRadius = [1 1 1 1 1 1 1 1];

% set up unit sphere information
numSphereFaces = 50
[unitSphereX, unitSphereY, unitSphereZ] = sphere(numSphereFaces)

% set up basic plot
figure
hold on

sphereCount = length(spheresRadius)

% for each given sphere, shift the scaled unit sphere by the
% location of the sphere and plot
for i=1:sphereCount
sphereX = spheresX(i) + unitSphereX*spheresRadius(i);
sphereY = spheresY(i) + unitSphereY*spheresRadius(i);
sphereZ = spheresZ(i) + unitSphereZ*spheresRadius(i);
surface(sphereX, sphereY, sphereZ);
end

hold off

shading interp
axis square
colormap pink

posted by onalark at 11:20 AM on October 31, 2007


« Older What's the point of subscription-based template...   |   Chile Willy Newer »
This thread is closed to new comments.