我正在将外部程序与 Mathematica 连接。我正在为外部程序创建一个输入文件。它是将 Mathematica 生成的图形中的几何数据转换为预定义的格式。这是一个几何示例。
图 1
在 Mathematica 中可以通过多种方式描述几何图形。一种费力的方法如下。
dat={{1.,-1.,0.},{0.,-1.,0.5},{0.,-1.,-0.5},{1.,-0.3333,0.},{0.,-0.3333,0.5},
{0.,-0.3333,-0.5},{1.,0.3333,0.},{0.,0.3333,0.5},{0.,0.3333,-0.5},{1.,1.,0.},
{0.,1.,0.5},{0.,1.,-0.5},{10.,-1.,0.},{10.,-0.3333,0.},{10.,0.3333,0.},{10.,1.,0.}};
Show[ListPointPlot3D[dat,PlotStyle->{{Red,PointSize[Large]}}],Graphics3D[{Opacity[.8],
Cyan,GraphicsComplex[dat,Polygon[{{1,2,5,4},{1,3,6,4},{2,3,6,5},{4,5,8,7},{4,6,9,7},
{5,6,9,8},{7,8,11,10},{7,9,12,10},{8,9,12,11},{1,2,3},{10,12,11},{1,4,14,13},
{4,7,15,14},{7,10,16,15}}]]}],AspectRatio->GoldenRatio]
这会生成 MMA 的 GraphicsComplex
格式所需的 3D 几何图形。
此几何图形被描述为我的外部程序的以下输入文件。
# GEOMETRY
# x y z [m]
NODES 16
1. -1. 0.
0. -1. 0.5
0. -1. -0.5
1. -0.3333 0.
0. -0.3333 0.50. -0.3333 -0.5
1. 0.3333 0.
0. 0.3333 0.5
0. 0.3333 -0.5
1. 1. 0.
0. 1. 0.5
0. 1. -0.5
10. -1. 0.
10. -0.3333 0.
10. 0.3333 0.
10. 1. -0.
# type node_id1 node_id2 node_id3 node_id4 elem_id1 elem_id2 elem_id3 elem_id4
PANELS 14
1 1 4 5 2 4 2 10 0
1 2 5 6 3 1 5 3 10
1 3 6 4 1 2 6 10 0
1 4 7 8 5 7 5 1 0
1 5 8 9 6 4 8 6 2
1 6 9 7 4 5 9 3 0
1 7 10 11 8 8 4 11 0
1 8 11 12 9 7 9 5 11
1 9 12 10 7 8 6 11 0
2 1 2 3 1 2 3
2 10 12 11 9 8 7
10 4 1 13 14 1 3
10 7 4 14 15 4 6
10 10 7 15 16 7 9
# end of input file
现在我从这个外部程序的文档中得到的描述非常简短。我在这里引用它。
- 第一个关键字 NODES 表示节点总数
节点。此行之后不应有任何注释或空行。接下来的几行包括
x、y、z 三个值节点坐标和行数必须与 number 相同
节点数。
- 下一个关键字是PANEL,说明我们有多少个面板。之后我们有线路
定义每个面板。第一个整数定义面板类型
- ID 1 - 四边形面板 - 由四个节点和四个相邻面板定义。
相邻面板是共享相同边(节点对)的面板,并且需要
速度和压力计算(方法 1 和 2)。缺少邻居(例如
后缘附近的面板)填充值 0(参见图 1)。
- ID 2 - 三角形面板 - 由三个节点和三个相邻面板定义。
- ID 10 - 尾流面板 - 是由四个节点和两个节点定义的四边形面板
位于后缘的(相邻)面板(尾流面板所在的面板)
应用库塔条件)。
- 面板类型 1 和 2 必须在输入文件中的类型 10 之前定义。
需要注意的是表面法线;定义面板的节点顺序应该是
逆时针。根据右手定则,如果手指弯曲以遵循编号,
拇指将显示应指向“向外”几何体的法线向量。
挑战!!
我们在名为 One.obj 的文件中获得了 3D CAD 模型,并且可以正常导出综合格斗。
cd = Import["One.obj"]
输出是 MMA Graphics3D
对象
现在,当 MMA 内部读取几何数据时,我可以轻松访问它们。
{ver1, pol1} = cd[[1]][[2]] /. GraphicsComplex -> List;
MyPol = pol1 // First // First;
Graphics3D[GraphicsComplex[ver1,MyPol],Axes-> True]
- 我们如何使用
ver1
和 中包含的顶点和多边形信息>pol1
并将它们写入文本文件,如上面输入文件示例中所述。在这种情况下,我们将只有 ID2 类型(三角形)面板。
- 使用 Mathematica 三角测量如何找到此 3D 对象的表面积。 MMA 中是否有可以计算表面积的内置函数?
- 现在无需创建唤醒面板或 ID10 类型元素。仅包含三角形元素的输入文件就可以了。
抱歉发了这么长的帖子,但这是我长期以来一直试图解决的一个难题。希望你们中的一些专家能够有正确的洞察力来破解它。
BR
I am interfacing an external program with Mathematica. I am creating an input file for the external program. Its about converting geometry data from a Mathematica generated graphics into a predefined format. Here is an example Geometry.
Figure 1
The geometry can be described in many ways in Mathematica. One laborious way is the following.
dat={{1.,-1.,0.},{0.,-1.,0.5},{0.,-1.,-0.5},{1.,-0.3333,0.},{0.,-0.3333,0.5},
{0.,-0.3333,-0.5},{1.,0.3333,0.},{0.,0.3333,0.5},{0.,0.3333,-0.5},{1.,1.,0.},
{0.,1.,0.5},{0.,1.,-0.5},{10.,-1.,0.},{10.,-0.3333,0.},{10.,0.3333,0.},{10.,1.,0.}};
Show[ListPointPlot3D[dat,PlotStyle->{{Red,PointSize[Large]}}],Graphics3D[{Opacity[.8],
Cyan,GraphicsComplex[dat,Polygon[{{1,2,5,4},{1,3,6,4},{2,3,6,5},{4,5,8,7},{4,6,9,7},
{5,6,9,8},{7,8,11,10},{7,9,12,10},{8,9,12,11},{1,2,3},{10,12,11},{1,4,14,13},
{4,7,15,14},{7,10,16,15}}]]}],AspectRatio->GoldenRatio]
This generates the required 3D geometry in GraphicsComplex
format of MMA.
This geometry is described as the following input file for my external program.
# GEOMETRY
# x y z [m]
NODES 16
1. -1. 0.
0. -1. 0.5
0. -1. -0.5
1. -0.3333 0.
0. -0.3333 0.50. -0.3333 -0.5
1. 0.3333 0.
0. 0.3333 0.5
0. 0.3333 -0.5
1. 1. 0.
0. 1. 0.5
0. 1. -0.5
10. -1. 0.
10. -0.3333 0.
10. 0.3333 0.
10. 1. -0.
# type node_id1 node_id2 node_id3 node_id4 elem_id1 elem_id2 elem_id3 elem_id4
PANELS 14
1 1 4 5 2 4 2 10 0
1 2 5 6 3 1 5 3 10
1 3 6 4 1 2 6 10 0
1 4 7 8 5 7 5 1 0
1 5 8 9 6 4 8 6 2
1 6 9 7 4 5 9 3 0
1 7 10 11 8 8 4 11 0
1 8 11 12 9 7 9 5 11
1 9 12 10 7 8 6 11 0
2 1 2 3 1 2 3
2 10 12 11 9 8 7
10 4 1 13 14 1 3
10 7 4 14 15 4 6
10 10 7 15 16 7 9
# end of input file
Now the description I have from the documentation of this external program is pretty short. I am quoting it here.
- First keyword NODES states total number of
nodes. After this line there should be no comment or empty lines. Next lines consist of
three values x, y and z node coordinates and number of lines must be the same as number
of nodes.
- Next keyword is PANEL and states how many panels we have. After that we have lines
defining each panel. First integer defines panel type
- ID 1 – quadrilateral panel - is defined by four nodes and four neighboring panels.
Neighboring panels are panels that share same sides (pair of nodes) and is needed for
velocity and pressure calculation (methods 1 and 2). Missing neighbors (for example for
panels near the trailing edge) are filled with value 0 (see Figure 1).
- ID 2 – triangular panel – is defined by three nodes and three neighboring panels.
- ID 10 – wake panel – is quadrilateral panel defined with four nodes and with two
(neighboring) panels which are located on the trailing edge (panels to which wake panel is
applying Kutta condition).
- Panel types 1 and 2 must be defined before type 10 in input file.
Important to notice is the surface normal; order of nodes defining panels should be
counter clockwise. By the right-hand rule if fingers are bended to follow numbering,
thumb will show normal vector that should point “outwards” geometry.
Challenge!!
We are given with a 3D CAD model in a file called One.obj and it is exported fine in MMA.
cd = Import["One.obj"]
The output is a MMA Graphics3D
object
Now I can get easily access the geometry data as MMA internally reads them.
{ver1, pol1} = cd[[1]][[2]] /. GraphicsComplex -> List;
MyPol = pol1 // First // First;
Graphics3D[GraphicsComplex[ver1,MyPol],Axes-> True]
- How we can use the vertices and polygon information contained in
ver1
and pol1
and write them in a text file as described in the input file example above. In this case we will only have ID2 type (triangular) panels.
- Using the Mathematica triangulation how to find the surface area of this 3D object. Is there any inbuilt function that can compute surface area in MMA?
- No need to create the wake panel or ID10 type elements right now. A input file with only triangular elements will be fine.
Sorry for such a long post but its a puzzle that I am trying to solve for a long time. Hope some of you expert may have the right insight to crack it.
BR
发布评论
评论(1)
Q1 和 Q2 很简单,您可以在问题中删除“挑战”标签。第三季度可能需要一些澄清。
Q1
更新Q1
主要问题是找到每个多边形的邻居。以下代码执行此操作:
您可以使用描述的低级输出函数此处 输出这些。我将把细节留给你(这是我对你的挑战)。
第二季度
机翼的面积是各个多边形的面积之和。各个面积的计算方法如下:
基于此 Mathworld 页面。
顺便说一句,该区域已签名,因此您可能需要使用
Abs
。更正
上述面积函数仅适用于二维中的一般多边形。对于 3D 中三角形的面积,可以使用以下公式:
Q1 and Q2 are easy enough that you could drop the "challenge" labels in your question. Q3 could use some clarification.
Q1
Update Q1
The main problem is to find the neighbor of each polygon. The following does this:
You can use the low level output functions described here to output these. I'll leave the details to you (that's my challenge to you).
Q2
The area of the wing is the summed area of the individual polygons. The individual areas can be calculated as follows:
based on this Mathworld page.
The area is signed BTW, so you may want to use
Abs
.CORRECTION
The above area function is only usable for general polygons in 2D. For the area of a triangle in 3D the following can be used: