当前位置: 首页 > news >正文

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]]

http://www.dtcms.com/a/173861.html

相关文章:

  • 状态模式 VS 策略模式
  • Kotlin密封类优化Android状态管理
  • 从设计到应用:大尺寸PCB打样的关键领域解析
  • 使用 Spring Boot 构建 REST API
  • 【大语言模型ChatGPT+Python】近红外光谱数据分析及机器学习与深度学习建模(近红外光谱数据分析、定性/定量分析模型代码自动生成等)
  • setup 函数在 Vue 3 中的作用是什么?什么时候会执行
  • 打成jar 包以后,运行时找不到文件路径?
  • WebRTC 服务器之SRS服务器性能优化配置
  • 在 GitLab 中部署Python定时任务
  • 私有仓库 Harbor、GitLab
  • 云计算训练营笔记day02(Linux、计算机网络、进制)
  • UE5 材质淡入淡出
  • 【工具使用-数据可视化工具】Apache Superset
  • 超表面加工流程
  • 前端知识-forwardRef
  • 区块链+数据库:技术融合下的应用革新与挑战突围
  • Kubernetes笔记(1)Kubernetes入门
  • 解锁RAG:AI 2.0时代的“知识外挂”是如何炼成的?
  • 开源之夏2025-VisActor 社区题目及参赛者选/培介绍
  • 当K8S容器没有bash时7种高阶排查手段
  • ESP32_IDF_idf.py指令详解
  • 阿里云前端Nginx部署完,用ip地址访问却总访问不到,为什么?检查安全组是否设置u为Http(80)!
  • Element-Plus-X开源程序是Vue3 + Element-Plus 开箱即用的企业级AI组件库前端的解决方案
  • 判断两个结构是否相同的一种方法
  • EasyRTC嵌入式音视频通信SDK技术,助力工业制造多场景实时监控与音视频通信
  • k8s service的类型
  • Stream和Collections工具类
  • vue3搭建后台管理系统
  • 18个国内wordpress主题推荐
  • CSS分栏布局