[Date Index]
[Thread Index]
[Author Index]
Re: Hole/Disk function
*To*: mathgroup at smc.vnet.net
*Subject*: [mg76091] Re: [mg76024] Hole/Disk function
*From*: Murray Eisenberg <murray at math.umass.edu>
*Date*: Wed, 16 May 2007 05:26:51 -0400 (EDT)
*Organization*: Mathematics & Statistics, Univ. of Mass./Amherst
*References*: <200705150845.EAA16651@smc.vnet.net>
*Reply-to*: murray at math.umass.edu
Let Mathematica do more of the work: Use Boole, e.g.:
holeyDisk[{x_,y_},holeSize_] :=Boole[x^2+y^2<=holeSize^2]
I made holeSize an additional parameter to holeyDisk rather than leave
it global. It's often safer and clearer to make all parameters
explicit like that.
If you prefer, you could use the form holeyDisk[x,y,holeSize], with
three arguments, instead of the two I used, where the first is a list of
the coordinates.
You could, if you wished, make holeSize optional by specifying some
default value, e.g.:
holeyDisk[{x_, y_}, holeSize_: 1] := Boole[x^2 + y^2 <= holeSize^2]
Note my use of x^2+y^2,=holeSize^2 so as to avoid taking the square
root. Probably of very little consequence in practice, but my intuition
is that calculating squares is more efficient than calculating square
roots. (I just tested doing tht with 100,000 random reals between 0 and
1, and there a difference on the order of 0.02 seconds.)
Mathieu G wrote:
> Hello,
> Is there a better way to define a Disk/Hole function than that?:
>
> DHole[x_, y_] := If[Sqrt[x^2 + y^2] <= HoleSize, 1, 0];
>
> I would like to use it for a convolution using the definition as shown
> in http://oldsite.vislab.usyd.edu.au/CP3/Four5/mod2-01.gif
>
> Best regards,
> MG
>
--
Murray Eisenberg murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
Prev by Date:
**How to use the Simpson 1/3 rule to write this program**
Next by Date:
**Re: Solve & RotationMatrix**
Previous by thread:
**Hole/Disk function**
Next by thread:
**Re: Hole/Disk function**
| |