Thanks @Michael E2 point out that quadratic paraboloid work. Here we use the definiton of differential of function to get the tangent plane for 2-variables function,see df
as in the code.
And we treat the general form of quadratic paraboloid f[x,y]=a-b*x^2-c*y^2;
or any other differentiable function f[x,y]=Sin[x + Cos[y]];
.
Clear[f, df, plot, data];
f[x_, y_] =
RandomReal[{0, 3}] - RandomReal[{2, 3}] x^2 - RandomReal[{2, 3}] y^2;
(*f[x_,y_]=1-x^2-y^2; *)
df[f_, {x0_, y0_}] =
f[x0, y0] + {Derivative[1, 0][f][x0, y0],
Derivative[0, 1][f][x0, y0]} . (## - {x0, y0}) &;
plot = Plot3D[f[x, y], {x, -1, 1}, {y, -1, 1}, Mesh -> None];
data = Table[
regs = MeshPrimitives[
ArrayMesh[ConstantArray[1, {n, n}],
DataRange -> {{-1, 1}, {-1, 1}}], 2];
Graphics3D[{Table[({x, y} |-> {x, y,
df[f, RegionCentroid@reg]@{x, y}}) @@@
MeshCoordinates[reg] // Polygon, {reg, regs}], plot[[1]],
RegionProduct[#, Point[{f[1, 1]}]] & /@ regs}, BoxRatios -> 1,
Boxed -> False], {n, 1, 10}];
ListAnimate[data, AnimationRunning -> True,
ControlPlacement -> Bottom]
TODO
I want to replace RegionCentroid@reg
to RandomPoint@reg
in the code to get some general definition of the area of surface,but now it seems need to be revided later since I doesn't know whether we need to use orthogonal projection to project the pieces of the surface to the tangent plane and how?
Clear[f, df, plot, data];
f[x_, y_] =
RandomReal[{0, 3}] - RandomReal[{2, 3}] x^2 - RandomReal[{2, 3}] y^2;
(*f[x_,y_]=1-x^2-y^2;*)
df[f_, {x0_, y0_}] =
f[x0, y0] + {Derivative[1, 0][f][x0, y0],
Derivative[0, 1][f][x0, y0]} . (## - {x0, y0}) &;
plot = Plot3D[f[x, y], {x, -1, 1}, {y, -1, 1}, Mesh -> None,
PlotPoints -> 80, MaxRecursion -> 4];
data = Table[
regs =
MeshPrimitives[
ArrayMesh[ConstantArray[1, {n, n}],
DataRange -> {{-1, 1}, {-1, 1}}], 2];
pts = RandomPoint /@ regs;
Graphics3D[{Table[({x, y} |-> {x, y,
Evaluate@df[f, pts[[i]]]@{x, y}}) @@@
MeshCoordinates[regs[[i]]] // Polygon, {i, Length@regs}],
plot[[1]], RegionProduct[#, Point[{f[1, 1]}]] & /@ regs},
BoxRatios -> 1, Boxed -> False], {n, 1, 10}];
ListAnimate[data, AnimationRunning -> True, ControlPlacement -> Bottom]
Test arbitrary function
- Tangent points are
RegionCentroid
.
Clear[f, df, plot, regs];
f[x_, y_] = Sin[x*y];
df[f_, {x0_, y0_}] =
f[x0, y0] + {Derivative[1, 0][f][x0, y0],
Derivative[0, 1][f][x0, y0]} . (## - {x0, y0}) &;
plot = Plot3D[f[x, y], {x, 0, 3}, {y, 0, 3}, PlotPoints -> 60,
MaxRecursion -> 4, Mesh -> None, PlotStyle -> Green];
n = 25;
regs = MeshPrimitives[
ArrayMesh[ConstantArray[1, {n, n}], DataRange -> {{0, 3}, {0, 3}}],
2];
Graphics3D[{Opacity[.5],
Table[({x, y} |-> {x, y, df[f, RegionCentroid@reg]@{x, y}}) @@@
MeshCoordinates[reg] // Polygon, {reg, regs}], plot[[1]]},
BoxRatios -> 1, Boxed -> False]
- Tangent Points are bottom left.
Clear[f, df, plot, n, regs];
f[x_, y_] = Sin[x*y];
df[f_, {x0_, y0_}][{x_, y_}] =
f[x0, y0] + {Derivative[1, 0][f][x0, y0],
Derivative[0, 1][f][x0, y0]} . ({x, y} - {x0, y0});
plot = Plot3D[f[x, y], {x, 0, 3}, {y, 0, 3}, PlotPoints -> 60,
MaxRecursion -> 4, Mesh -> None, PlotStyle -> Darker@Cyan];
n = 25;
regs = MeshPrimitives[
ArrayMesh[ConstantArray[1, {n, n}], DataRange -> {{0, 3}, {0, 3}}],
2];
Graphics3D[{Opacity[.8],
Table[({x, y} |-> {x, y,
df[f, First@*Transpose@*RegionBounds@reg]@{x, y}}) @@@
MeshCoordinates[reg] // Polygon, {reg, regs}], plot[[1]]},
BoxRatios -> 1, Boxed -> False]