1
$\begingroup$

I want to divide a surface f[x_, y_] := (1.4025 - (-0.2 + x)^2 - (-0.2 + y)^2)^0.5 + 0.15 into meshes corresponding to the region x0y

f[x_, y_] := (1.4025 - (-0.2 + x)^2 - (-0.2 + y)^2)^0.5 + 0.15;
X[x_, y_] := Evaluate@D[f[x, y], x]
Y[x_, y_] := Evaluate@D[f[x, y], y]
GetRegion[n_, 
  m_] := {TwoD$Points = Outer[List, #, #] &@Subdivide[0, 1, n]; 
   TwoD$Points = (Flatten[#, 1][[{1, 2, 4, 3}]] & /@ 
      Flatten[Partition[TwoD$Points, {2, 2}, 1], 1]);
   TwoD$Points[[m]]} // Flatten[#, 1] &
GetLine[n_, 
  m_] := {TwoD$Points = Outer[List, #, #] &@Subdivide[0, 1, n]; 
   TwoD$Points = (Flatten[#, 1][[{1, 2, 4, 3}]] & /@ 
      Flatten[Partition[TwoD$Points, {2, 2}, 1], 1]);
   ThreeD$Points = Map[Flatten[{#, 0}] &, TwoD$Points, {2}][[m]]; 
   List[ThreeD$Points, 
     Apply[{#1, #2, f[#1, #2]} &, ThreeD$Points, 2]] // Transpose} // 
  Flatten[#, 1] &
NormalLine[n_, 
  m_] := {TwoD$Points = Outer[List, #, #] &@Subdivide[0, 1, n]; 
   TwoD$Points = (Flatten[#, 1][[{1, 2, 4, 3}]] & /@ 
      Flatten[Partition[TwoD$Points, {2, 2}, 1], 1]);
   ThreeD$Points = Map[Flatten[{#, 0}] &, TwoD$Points, {2}][[m]]; 
   List[ThreeD$Points, 
     Apply[{#1, #2, f[#1, #2]} &, ThreeD$Points, 2]] // Transpose} // 
  Flatten[#, 1] &


Manipulate[region = GetRegion[n, m]; 
 Show[Plot3D[{f[x, y], 0}, {x, 0, 1}, {y, 0, 1}, 
   MeshFunctions -> {#1 &, #2 &}, Mesh -> n - 1, 
   MeshShading -> 
    ReplacePart[
     ConstantArray[Automatic, {n, n}], {Mod[m, n, 1], Ceiling[m/n]} ->
       Red], PlotRange -> {{0, 1.6}, {-0.2, 1.4}, {0, 1.6}}, 
   BoxRatios -> Automatic], 
  Plot3D[X[(region[[1, 1]] + region[[3, 1]])/
       2, (region[[1, 2]] + region[[2, 2]])/
       2] (x - (region[[1, 1]] + region[[3, 1]])/2) + 
    Y[(region[[1, 1]] + region[[3, 1]])/
       2, (region[[1, 2]] + region[[2, 2]])/
       2] (y - (region[[1, 2]] + region[[2, 2]])/2) + 
    f[(region[[1, 1]] + region[[3, 1]])/
      2, (region[[1, 2]] + region[[2, 2]])/2], {x, region[[1, 1]], 
    region[[3, 1]]}, {y, region[[1, 2]], region[[2, 2]]}, 
   Mesh -> None, PlotStyle -> {Blue, Opacity[0.6]}], 
  Graphics3D[{Thick, Dashed, Pink, Line@GetLine[n, m]}]], {{n, 4, 
   "Divide quantity"}, 3, 30, 1, 
  Appearance -> "Open"}, {{m, 1, "Division number of sub region j"}, 
  1, n^2, 1, Appearance -> "Open"}]

But I can't match the jth red mesh in xoy with the surface f[x_, y_] := (1.4025 - (-0.2 + x)^2 - (-0.2 + y)^2)^0.5 + 0.15.What should I do to make the corresponding part of the surface red? enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$

A simple answer:

  f[x_, y_] := (1.4025 - (-0.2 + x)^2 - (-0.2 + y)^2)^0.5 + 0.15;
    Manipulate[
     Plot3D[{f[x, y], 0}, {x, 0, 1}, {y, 0, 1}, 
      MeshFunctions -> {#1 &, #2 &}, Mesh -> n - 1, 
      MeshShading -> 
       ReplacePart[
        ConstantArray[Automatic, {n, n}], {Mod[m, n, 1], Ceiling[m/n]} -> 
         Red], PlotRange -> {{0, 1.6}, {-0.2, 1.4}, {0, 1.6}}, 
      BoxRatios -> Automatic], {{n, 4, "Divide quantity"}, 3, 30, 1, 
      Appearance -> "Open"}, {{m, 1, "Division number of sub region j"}, 
      1, n^2, 1, Appearance -> "Open"}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.