# What is the meaning of this code section?

I like to know the meaning of this:

Total[#4 Boole[Norm[({x, y} - #1).RotationMatrix[#3]/#2]^2 < 1] & @@@
Data]


I need to make a slight modification to a code for generating Shepp Logan phantom and I need to be sure I am going about it in the right manner.

Data = {{{0, 0}, {0.92, 0.69}, 90°, 2}, {{0, -0.0184}, {0.874, 0.6624}, 90°,-0.9},{{0.22, 0}, {0.31, 0.11}, 72°, -0.1}, {{-0.22, 0}, {0.41, 0.16}, 108°, -0.1},{{0, 0.35}, {0.25, 0.21}, 90°, 0.3}, {{0, 0.1}, {0.046, 0.046}, 0, 0.3},{{0, -0.1}, {0.046, 0.046}, 0, 0.3}, {{-0.08, -0.605}, {0.046, 0.023}, 0, 0.3},{{0.06, -0.605}, {0.046, 0.023}, 90°, 0.3}, {{0, -0.605}, {0.023, 0.023}, 0, 0.3}};


A table representing this table is available here! Thanks.

This code defines a function,

#4 Boole[Norm[({x, y} - #1).RotationMatrix[#3]/#2]^2 < 1] &


applies it to each element of Data, and finally sums the results for all elements of Data. Because there are four variable in this function (#1, etc.), the elements of Data must themselves be lists of four elements. For instance,

Data = {{{1.27304,2.73124}, 2.87282, 2.85453, 1.21836},
{{4.44383,5.74962}, 4.78388, 1.48409, 0.19928},
{{5.35696,4.73832}, 2.24427, 6.20758, 3.08224}}


x and y also must be defined. For instance,

x = 1; y = 3;


Applying the function to the first element of Data,

1.21836 Boole[Norm[({x, y} - {1.27304, 2.73124}).RotationMatrix[2.85453]/2.87282]^2 < 1]
(* 1.21836 *)


(See Mathematica documentation for Boole, Norm, Dot, and RotationMatrix.)

@@@ applies the function to every such element of Data, and Total sums the results. (See Mathematica documentation for Apply and Total.)

Total[#4 Boole[Norm[({x, y} - #1).RotationMatrix[#3]/#2]^2 < 1] & @@@ Data]
(* 1.41764 *)

• Many thanks for your kind and detailed answer @bbgodfrey. I have added the definition of "Data" to my question. Would this produce any different narrative?
– Dean
May 1, 2020 at 17:56
• @Dean No, it should not. However, please provide me with your values for {x,y}, so that I can take a harder look. May 1, 2020 at 19:23
• I have inserted a link to the table respresenting this data as a modification to my question. However, the angle is in radians and not in degrees as in the above data. If you need me to change them to degress, please let me know. Many thanks!
– Dean
May 1, 2020 at 20:42
• @Dean For reasons I do not yet understand, f = Total[#4 Boole[Norm[({x, y} - #1).RotationMatrix[#3]/#2]^2 < 1] & @@@ Data]; DensityPlot[f, {x, -1, 1}, {y, -1, 1}, ColorFunction -> GrayLevel, Frame -> False, Mesh -> False, PlotPoints -> 100] gives a much better plot than DensityPlot[Total[#4 Boole[Norm[({x, y} - #1).RotationMatrix[#3]/#2]^2 < 1] & @@@Data], {x, -1, 1}, {y, -1, 1}, ColorFunction -> GrayLevel, Frame -> False, Mesh -> False, PlotPoints -> 100]. Of course, it is faster too. May 1, 2020 at 23:22
• @Dean By the way, it does not matter whether you use "Mesh -> False". May 2, 2020 at 1:27