Manipulate[
Grid[{{Show[
ParametricPlot3D[{1.25Cos[t], 1.25 Sin[t],s+2-2w},{s,0,.25},{t,0,2Pi},PlotStyle->Directive[Opacity[1],Gray],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{r Cos[t], r Sin[t],2.25-2w},{r,0,1.25},{t,0,2Pi},PlotStyle->Directive[Opacity[1],Gray],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{r Cos[t], r Sin[t],2-2w},{r,0,1.25},{t,0,2Pi},PlotStyle->Directive[Opacity[1],Gray],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{1.25Cos[t], 1.25 Sin[t],s-2.25+2w},{s,0,.25},{t,0,2Pi},PlotStyle->Directive[Opacity[1],Gray],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{r Cos[t], r Sin[t],-2.25+2w},{r,0,1.25},{t,0,2Pi},PlotStyle->Directive[Opacity[1],Gray],Mesh->None],
ParametricPlot3D[{r Cos[t], r Sin[t],-2+2w},{r,0,1.25},{t,0,2Pi},PlotStyle->Directive[Opacity[1],Gray],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{(1-s/2) Cos[t],(1-s/2) Sin[t],Max[0,-s+2 ]},{s,Min[2-(2^(2/3) (2 \[Pi]-Min[2Pi,3 V((w^2)/(.04))])^(1/3))/\[Pi]^(1/3)-w,1.99],2},{t,0, 2 Pi},PlotStyle->Directive[Opacity[1],Hue[a]],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{r Cos[t], r Sin[t],Max[0,(2^(2/3) (2 \[Pi]-Min[2Pi,3 V((w^2)/(.04))])^(1/3))/\[Pi]^(1/3)-w]},{r,0, .000000000001+w+((2^(2/3) (2 \[Pi]-Min[2Pi,3 V((w^2)/(.04))])^(1/3))/\[Pi]^(1/3)-w)/2},{t,0,2Pi},PlotStyle->Directive[Opacity[1], Hue[a]],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{r Cos[t], r Sin[t], Min[0,-(2^(2/3) (2 \[Pi]-Min[2Pi,3 V((w^2)/(.04))])^(1/3))/\[Pi]^(1/3)]},{r, 0, .00000000001+w+((2^(2/3) (2 \[Pi]-Min[2Pi,3 V((w^2)/(.04))])^(1/3))/\[Pi]^(1/3)-w)/2},{t,0,2Pi},PlotStyle->Directive[Opacity[1],Hue[a]],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{(1-s/2) Cos[t],(1-s/2) Sin[t],Min[0,s -2 ]},{s,w,2},{t,0, 2 Pi},PlotStyle->Directive[Opacity[.2],Gray],Mesh->None, Lighting->"Neutral"],ParametricPlot3D[{(1-s/2) Cos[t],(1-s/2) Sin[t],Max[0,-s + 2 - w]},{s,w,2},{t,0, 2 Pi},PlotStyle->Directive[Opacity[.2],Gray],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{(1-s/2) Cos[t],(1-s/2) Sin[t],Min[0,s-2+ w]},{s,w,Min[2-(2^(2/3) (2 \[Pi]-Min[2Pi,3 V((w^2)/(.04))])^(1/3))/\[Pi]^(1/3)-w,2]},{t,0, 2 Pi},Mesh->None, PlotStyle->Directive[Opacity[1],Hue[a]], Lighting->"Neutral"], ParametricPlot3D[{(w/2) Cos[t],(w/2) Sin[t], b},{t,0,2Pi}, {b, -2 + w, 0}, PlotStyle->Directive[Opacity[1], Hue[a]],Mesh->None, Lighting->"Neutral"],PlotRange->All,ImageSize->{300,300}, SphericalRegion-> True]},{Row[{Text["time to empty = "], Text[2Pi (.04)/(3w^2)],Text[" seconds"]}]}}],{start,ControlType->None},{end,ControlType->None},
{{V,.01,"time (seconds)"},0.01,34,.01,ControlType->Animator,AnimationRate->1,AnimationRunning->False,ImageSize->Small},
{{w,.05,"neck width (millimeters)"}, .05, .3,.01,Appearance->"Labeled"},
{{a,0,"color of sand"}, 0, 1,Appearance->"Labeled"}]
这个链接展示了一个模拟沙漏流动的网页应用程序,可以用来演示放置不同颜色的沙子对于流动时间的影响。该应用程序基于Wolfram语言实现。
要创建“场景”或可视化对象,您可以使用像blender这样的软件,它可以导出VRML场景,或者手动编写VRML(这是一个非常简单的任务)。
在基础设施方面,MATLAB拥有VRML工具包,而Python则有非常广泛的模块选择,可以处理VRML(例如,请参见this和this链接)。
举个更具体的例子:
假设有一些仿真输出y
和一个模板VRML文件:
#VRML V2.0 utf8
Transform {
translation 0 0 0
children [
Shape { geometry Box {2,2,zSize} }
]
}
data = (Read contents of VRML file as string data).
for n in [0..1000]:
y = getSimulationOutput(aParameterVector)
renderData = substitute(data, "zSize", y) #This function could be provided by a template module like jinja for example.
simulationFrame = renderVRML(renderData)
saveImage(simulationFrame)
请注意:有关Jinja的更多信息可以在此处找到 - 在上面的内联链接中注释未正确呈现。
返回文件并将不同的元素绑定到不同的数量(例如,更改可以旋转、缩放、平移盒子的变换,或通过分配不同的颜色来更改盒子的外观),您可以为模拟创建任何类型的“仪表板”输出... 包括不规则六边形。
这种技术是数据驱动文档的直接应用,但适用于不同的基质(而不是HTML或SVG)。
希望这可以帮助到您。
fill
和fill3
应该能够实现。以下是一个示例代码,假设您的六边形由两个宽度w1
和w2
以及d1
和d2
参数来参数化,它们是边的长度:function draw_hexagon(w1, w2, d1, d2)
a=(w1-w2)/2;
b1=sqrt(d1^2 - a^2);
b2=sqrt(d2^2 - a^2);
xs=[-w1/2, w1/2, w2/2, w1/2, -w1/2, -w2/2];
ys=[b1, b1, 0, -b2, -b2, 0];
fill(xs, ys, 'b')
axis square
grid on
end
w1=4, w2=2, d1=2, d2=3
生成以下内容:
function draw_hexagon_3d(w1, w2, d1, d2)
a=(w1-w2)/2;
b1=sqrt(d1^2 - a^2);
b2=sqrt(d2^2 - a^2);
xs=[-w1/2, w1/2, w2/2, w1/2, -w1/2, -w2/2];
ys=[0, 0, 0, 0, 0, 0];
zs=[b1, b1, 0, -b2, -b2, 0];
fill3(xs, ys, zs, 'b')
grid on
axis square
end
我和我的同事讨论了这个问题。 他建议创建一个三角形网络,但也指出了非凸多边形的一般算法。
assemmbly
并通过inittri
构建三角网结构f
通过bilin_assembly
构建(因为之前这样做过,但不一定是最优选择)将具有两个口的六边形分成两个梯形
以下语法基于我在2013年对代码的修改,但主要参考了Claes Johnson的书《用有限元方法求解偏微分方程的数值解》的描述。
现在考虑汇编语言的语法,以简化泊松问题(稍后必须在此处进行精细处理)
% [S,f]=assemblyGlobal(loadfunction,mesh)
%
% loadfunction = function on the right-hand side of the Poisson equation
% mesh = mesh structure on which the assembly is done
%
% S = stiffness matrix of the Poisson problem
% f = load vector corresponding to loadfunction
我们需要双线性汇编的语法在哪里
% function B=bilin_assembly(bilin,mesh)
%
% bilin = function handle to integrand of the bilinear form
% given as bilin(u,v,ux,uy,vx,vy,x,y), where
% u - values of function u
% v - values of function v
% ux - x-derivative of function u
% uy - y-derivative of function u
% vx - x-derivative of function v
% vy - y-derivative of function v
% x - global x-coordinate
% y - global y-coordinate
% mesh = mesh structure on which the matrix will be assembled
%
% B = matrix related to bilinear form bilin
初始化三角网格的语法
% function mesh = inittri(p,t)
%
% p = nodes
% t = triangles
%
% mesh = trimesh structure corresponding to (p,t)
%
% TRIMESH STRUCTURE :
%
% p = nodes in a 2xN-matrix
%
% t = triangles in a 3xN- matrix (nodes of the triangles as indeces to the p- matrix).
%
% edges = a matrix of all edges in the mesh. Each column is an edge :
% [n1 ; n2] where n1 < n2;
%
% t2e = a matrix connecting triangle's and edges's.
% Each column corresponds to a triangle and has
% triangle's edges in the order n1->n2, n2->n3,
% n1->n3.
%
% e2t = inverse of t2e.
由于版权问题和答案会变得很长,我没有在这里发布完整的源代码。然而,所有算法都基于第一个源,因此任何研究人员都可以创建它们。我认为这种FEM方法是找到最佳网格的唯一途径。
还有一些算法可以为一般非凸多边形创建网格。Margus的答案提供的网格可能就是由这样的算法产生的。
我正在尝试不同的产品来可视化孔洞、不同的几何形状和不同的材料。Ansys是一个有前途的解决方案。