Mathematica:删除图形基元 [英] Mathematica: Removing graphics primitives
问题描述
鉴于 g
是一个带有诸如 Line
s 和 Polygon
s 之类的基元的图形对象,您如何删除其中的一些?要向现有图形对象添加更多基元,我们可以使用 Show
,例如: Show[g, g2]
其中 g2
是另一个图形对象与其他原语.但是如何删除不需要的原始对象呢?看看下面的
Given that g
is a graphics object with primitives such as Line
s and Polygon
s, how do you remove some of them? To add more primitives to an existing graphics object we can use Show
, for instance: Show[g, g2]
where g2
is another graphics object with other primitives. But how do you remove unwanted primitive objects? Take a look at the following
ListPlot3D[{{0, 0, 1}, {1, 0, 0}, {0, 1, 0}, {1, 1, 0}}, Mesh -> {1, 1}]
现在,对于输入表单:
InputForm[
ListPlot3D[{{0, 0, 1}, {1, 0, 0}, {0, 1, 0}, {1, 1, 0}}, Mesh -> {1, 1}]
]
要从此对象创建线框,我们要做的就是移除多边形.另外,我们还可以移除顶点法线,因为它们对线框没有贡献.
To create a wire frame from this object all we have to do is remove the polygons. As an extra we can also remove the vertex normals since they don't contribute to the wireframe.
请注意,要制作线框,我们可以简单地设置 PlotStyle ->None
作为 ListPlot3D
中的一个选项.这摆脱了 Polygon
s 但不会删除 VertexNormals
.
Notice that to make a wireframe we can simply set PlotStyle -> None
as an option in ListPlot3D
. This gets rid of the Polygon
s but doesn't remove the VertexNormals
.
澄清问题.鉴于
g = ListPlot3D[{{0, 0, 1}, {1, 0, 0}, {0, 1, 0}, {1, 1, 0}}, Mesh -> {1, 1}]
如何从 g
中删除一些图形基元,以及如何删除一些选项,即 VertexNormals
?注意:选项 VertexNormals
是 GraphicsComplex
的一个选项.
How do you remove some of the of the graphics primitives from g
and how do you remove some of the options, i.e. VertexNormals
? Note: option VertexNormals
is an option of GraphicsComplex
.
如果这是不可能的,那么下一个问题可能是,您如何获取用于生成 g
的数据,以使用从 g 获得的一些数据生成新的图形对象
.
If this is not possible then maybe the next question would be, how do you obtain the data used to generate g
to generate a new graphics object with some of the data obtained from g
.
推荐答案
一种方法是使用转换规则.鉴于你的
One way is to use transformation rules. Given your
im = ListPlot3D[{{0, 0, 1}, {1, 0, 0}, {0, 1, 0}, {1, 1, 0}}, Mesh -> {1, 1}]
你可以这样做
newim = im /. {_Polygon :> Sequence[], (VertexNormals -> _) :> Sequence[]}
或者,更紧凑地使用 Alternatives
:
or, more compactly using Alternatives
:
newim = im /. _Polygon | (VertexNormals -> _) :> Sequence[]
您也可以使用 DeleteCases
来获得类似的效果:
You could also use DeleteCases
to get a similar effect:
newim = DeleteCases[im, (_Polygon | (VertexNormals -> _)), Infinity]
这篇关于Mathematica:删除图形基元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!