欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > Mathematica中的ResourceFunction

Mathematica中的ResourceFunction

2025/5/7 13:26:16 来源:https://blog.csdn.net/weixin_66585495/article/details/147749449  浏览:    关键词:Mathematica中的ResourceFunction

在Mathematica中,ResourceFunction 的作用是访问并调用 Wolfram Function Repository(Wolfram 函数仓库)中用户或官方贡献的预定义函数。

这里给出两个使用案例:MortonCurve和LevyCCurve。

MortonCurve

和Peano曲线和Sierpinski曲线一样,MortonCurve也是一种平面填充曲线,不过填充曲线为‘Z’-型线。

ResourceFunction["MortonCurve"][n] gives the line segments representing the nth-step Morton (z-order) curve.

在实际使用中,我们可以将ResourceFunction["MortonCurve"]定义为一个新的函数,然后像调用PeanoCurve一样,调用这个函数。

使用如下代码:

可以看到如下对比图:

也可以指定坐标范围:

Graphics[mortonC[3, DataRange -> {{0, 1}, {0, 1}}], PlotRange -> 2, Axes -> True]

和Peano曲线一样,也可以做曲线的参数化:

BSplineFunction[mortonC[3, DataRange -> {{-1, 1}, {-1, 1}}][[1]], SplineDegree -> 1]; ParametricPlot[%[t], {t, 0, 1}, PlotPoints -> 400]

也可以使用如下方式:

Graphics[{Thickness[Large], mortonC[3] /. Line -> BSplineCurve}]

有了参数化之后,可以感测曲线的填充平面过程:

tempFunc00 = BSplineFunction[mortonC[6, DataRange -> {{-1, 1}, {-1, 1}}][[1]], SplineDegree -> 1]; Animate[ParametricPlot[tempFunc00[t], {t, 0, n}, PlotPoints -> 400, PlotRange -> {{-1, 1}, {-1, 1}}], {n, 0.01, 1, 0.01}]

也可以使用如下方式来观察:

With[{curve = mortonC[6]}, Manipulate[ Graphics[{curve, Red, Thick, Line[Take[First[curve], i]]}, ImageSize -> Medium], {i, 1, 4096, 1}, SaveDefinitions -> True]]

LevyCCurve

Levy C 曲线的调用语法为:

ResourceFunction["LevyCCurve"][n] generates the line segments of the Lévy C curve with n iterations. equivalent to ResourceFunction["LevyCCurve"][{{-1,0},{1,0}},n].

基本使用方法,和MortonCurve一样:

使用代码:

GraphicsGrid[ { {Graphics[levyC[2]], Graphics[levyC[3]]}, {Graphics[levyC[4]], Graphics[levyC[5]]} } ]

可以看到对比图:

从图中可以看到:Levy C曲线,有自交。因此,不能使用BSplineFunction进行参数化。

这里提供两个比较有意思的案例,来自于官方文档的。

Graphics[{ResourceFunction["LevyCCurve"][ Line[{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}], 10], ResourceFunction["LevyCCurve"][ Line[Reverse@{{3, 0}, {3, 1}, {4, 1}, {4, 0}, {3, 0}}], 10]}]

pts = First@levyC[10]; colors = Blend[{Red, Blue, Green, Orange}, #] & /@ Subdivide[Length[pts] - 1]; Graphics[Line[pts, VertexColors -> colors]]

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词