|Jan6-11, 08:42 AM||#1|
MATLAB discretization of a 2D circular surface
I am trying to model the magnetic force between two cylindrical identical sized permanent magnets. I am using the Charge/Coulombian model to do this. This assumes that all of the "magnetic charge" is on the pole ends of the magnet, i.e. the flat surfaces at the top and bottom of each cylinder.
I am doing these calculations in MATLAB. I have managed to write code which produces a graph of force on one magnet, say M1 due to a second magnet, say M2, but this code is cumbersome and very slow so I need to find a more efficient way of discretizing the magnet surfaces.
At the moment I am dividing these circular surfaces into equal sized uniform square facets. Then I iterate along the X and Y axis, which is what is slowing me down, to get the central positioni of each facet, but this gives me some facets which are not inside the circular surfaces, so I am using an if statement and pythagoras to determine whether my point lies in my circle or is merely on the square which surrounds my circle.
This is all very slow so what I was goin to try and do was somehow use the radius of the circle to plot a circular surface area, and then divide this circle into the eqqual sized square facets as before. However I don't know how to read in this circular surface area so that I will have a 2D array which contains every single facet point - I am new to MATLAB
Any help or ideas would be much appreciated
|Jan6-11, 02:11 PM||#2|
One quick way is to create a square lattice of points with meshgrid, then use a simple if statement to get a logical mask that indicates whether each point is inside or outside the circle.
Example, where a = radius of circle and npts = # of squares you want to put across the diameter.
xvec = linspace(-a,a,npts);
[x,y] = meshgrid(xvec,xvec);
mask = x.^2 + y.^2 <= a^2 * ones(npts,npts);
% Mask has logical 1's for points inside the circle
% If you plot x,y, you'll see that all points outside the circle are masked out.
BTW, please it's better not to post in bold letters. They are hard to read.
|Similar Threads for: MATLAB discretization of a 2D circular surface|
|u_t = div(A\nabla u)||Differential Equations||1|
|discretization of Lz||Quantum Physics||11|
|Discretization of the Poisson Equation across Heterointerface||Advanced Physics Homework||1|
|surface cut function in matlab?||Math & Science Software||4|