Dr.*_*ius 8 wolfram-mathematica
我想在可见的Mesh交叉点绘制点,如下所示:
Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, Mesh -> {1, 4}, Boxed -> False]
Run Code Online (Sandbox Code Playgroud)
期望的输出:
我可以根据PlotRange和Mesh基数来计算Mesh的位置,并在那里绘制点,但我认为应该有一种更简单的替代方法.
一个很大的优点是能够根据功能值选择点颜色.此外,标记点将是美好的.
有任何想法吗?
对于它的价值,我也喜欢简单的解决方案.此外,表面和点都很容易使用相同的着色功能:
g = Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, Mesh -> {1, 4}, Boxed -> False, ColorFunction -> "Rainbow"];
p = ListPointPlot3D[Table[{x, y, Sin[x + y^2]}, {x, -3, 3, (3 - (-3))/(1 + 1)}, {y, -2, 2, (2 - (-2))/(4 + 1)}], ColorFunction -> "Rainbow", PlotStyle -> PointSize[Large]];
Show[g, p]
Run Code Online (Sandbox Code Playgroud)
编辑: 如果我们想把它变成一个自定义的myPlot3D,我想以下应该做:
myPlot3D[f_, {x_, xmin_, xmax_}, {y_, ymin_, ymax_},
Mesh -> {i_Integer, j_Integer}, opts : OptionsPattern[]] :=
Module[{g =
Plot3D[f, {x, xmin, xmax}, {y, ymin, ymax}, Mesh -> {i, j},
Evaluate@FilterRules[{opts}, Options[Plot3D]]],
stx = (xmax - xmin)/(i + 1),
sty = (ymax - ymin)/(j + 1), pts},
pts = ListPointPlot3D[
Table[{x, y, f}, {x, xmin + stx, xmax - stx, stx}, {y,
ymin + sty, ymax - sty, sty}],
Evaluate@FilterRules[{opts}, Options[ListPointPlot3D]]];
Show[g, pts]];
Run Code Online (Sandbox Code Playgroud)
请注意,选项适用于两个图,但首先进行过滤.我还删除了绘图轮廓上的点.例如,
myPlot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, Mesh -> {4, 10},
Boxed -> False, ColorFunction -> "Rainbow", Axes -> False,
PlotStyle -> PointSize[Large]]
Run Code Online (Sandbox Code Playgroud)
会给出结果
这是一种非常糟糕的方法:抓住输出中的网格线并寻找交叉点.由于输出是a,因此非常可行GraphicsComplex
.
首先,找到图形复合体中网格线点的索引:
g=Plot3D[Sin[x+y^2],{x,-3,3},{y,-2,2},Mesh->{1,4},Boxed->False];
meshlineptindices=First/@Cases[g, _Line, Infinity]
Run Code Online (Sandbox Code Playgroud)
现在,成对地遍历这些线并寻找交叉点.以下,用于NestWhile
递归查看原始网格线列表的更短和更短子列表的所有对(第一行,另一行).生成的交叉点通过Sow
以下方式返回:
intesectionindices=
Flatten@Reap@NestWhile[(
Sow@Outer[Intersection,{First[#]},Rest[#],1];
Rest[#]
)&, meshlineptindices, Length[#]>0&]
Out[4]= {1260,1491,1264,1401,1284,1371,1298,1448,1205,1219,1528,1525,1526,1527}
Run Code Online (Sandbox Code Playgroud)
查找以下指数GraphicsComplex
:
intesections = Part[g[[1,1]],intesectionindices]
Out[5]= {{-3.,-1.2,-0.997667},{3.,-1.2,-0.961188},<...>,{0.,1.2,0.977754}}
Run Code Online (Sandbox Code Playgroud)
最后,将这些点与原始图形一起显示:
Show[g,Graphics3D[{Red,PointSize[Large],Point[intesections]}]]
Run Code Online (Sandbox Code Playgroud)
HTH
更新:要获得彩色点,您可以使用
Graphics3D[{PointSize[Large],({colorfunction[Last@#],Point[#]}&)/@intesections]}]
Run Code Online (Sandbox Code Playgroud)