Assignment for Introduction to Computational Thinking
A superellipse is defined by the inequality !!"!#+!$%!#≤1, where 𝑥 and 𝑦 are the Cartesian coordinates, and 𝑎 and 𝑏 are the length of long and short axes with 𝑛>2 the deformation parameter. An example of a superellipse centered at 𝒓& with 𝑎=2, 𝑏=1 and 𝑛=2.5 is shown in the figure below, where 𝒆! and 𝒆$ are the unit vectors pointing to the direction of long and short axes, respectively, and 𝒆!⊥ 𝒆$. All vectors here are column vectors.
Questions:
- Write a program “CalVolume(a,b,n)” to numerically calculate the area 𝑆 of a superellipse for given 𝑎 and 𝑏. For 𝑎=2, 𝑏=1, plot 𝑆 as a function of 𝑛∈[2,10], and compare your result with the analytical formula 𝑆='!"!#"%√)+,-!#.+!$-!#., where Γ(∙) is the Gamma function. (20 marks)
- Write a Matlab program “DrawSuperellipse(𝒓&,𝑎,𝑏,𝑛,𝒆!,𝒆$)”to draw a superellipse entered at 𝒓& for a given 𝑎, 𝑏, 𝑛, 𝒆! and 𝒆$. The input of the program is {𝒓&,𝑎,𝑏,𝑛,𝒆!,𝒆$}. (20 marks)
- Write a program “Distance(𝒓,,𝑎,,𝑏,,𝑛,𝒆!,,𝒆$,, 𝒓/,𝑎/,𝑏/,𝑛,𝒆!/,𝒆$/)” using the Newton’s method to calculate the shortest distance between two points on two superellipses {𝒓,,𝑎,,𝑏,,𝑛,𝒆!,,𝒆$,} and {𝒓/,𝑎/,𝑏/,𝑛,𝒆!/,𝒆$/} where 𝑎,=𝑏,=𝑎/=𝑏/=1 for 2<𝑛≤3.4. The program should return a value of 0 if two superellipses are overlapped. Use your program to calculate the shortest distance between two superellipses with the location and orientation listed in Table 1, and draw the two closest points on the two superellipses. (60 marks) Table 1 𝒓,=(0,0), 𝒆!,=(1,0), 𝒆$,=(0,1), 𝑎,=𝑏,=𝑎/=𝑏/=1 𝒓/ 𝒆!/ 𝒆$/ 𝑛 (3.0187, 2.6204) (-0.6737, -0.7390) (0.7390, -0.6737) 2.5 (2.7188, 0.4760) (0.8180, 0.5752) (-0.5752, 0.8180) 3.0 (2.3411, 1.0204) (0.6111,0.7916) (-0.7916, 0.6111) 3.4 exeyr0 2 (3.3629, 0.9741) (0.6441, 0.7650) (-0.7650, 0.6441) 3.5 (1.0171, 3.7171) (0.5914, 0.8064) (-0.8064, 0.5914) 5.0 (3.2571, 1.3999) (-0.0472, 0.9989) (-0.9989, -0.0472) 7.0