如何制作有向圆弧(或有向曲线)?
我想在 Mathematica 中显示有向圆弧,使用像 Arrow
这样简单的东西。我能想到的最好的例子就是将一个箭头
钉在圆弧一端的示例。但我怀疑有一种更直接的方法可以达到同样的效果。
start=\[Pi];
Manipulate[
Graphics[{
Arrow[{{Cos[\[Theta] + If[\[Theta] < start, .01, -.01]],
Sin[\[Theta] + If[\[Theta] < start, .01, -.01]]},
{Cos[\[Theta]], Sin[\[Theta]]}}],
Circle[{0, 0}, 1, {start, \[Theta]}]},
PlotRange -> 2],
{{\[Theta], .7 start}, 0, 2 start}
]
Arrow
接受 BSplineCurves
和 BezierCurves
>但我无法让它们保持在圆弧上。 Tube
接受 3D 曲线的公式,但我不知道如何让它在 2D 中工作。
欢迎所有建议。如果您的解决方案适用于任何二维曲线,那就更好了!
结语:
我从这些建议中学到了很多东西: Mark McClure 表明,当给定点列表时,Arrow 本身可以处理需求。
yoda 使用 ParametricPlot 给出了一个相当通用的解决方案。
我最终发现贝利萨留的建议最有帮助。他的方法是对熟悉的图形对象进行微小的变化。最后,我谨慎地选择定义一个新对象arcArrow
,它使用Circle
的参数:center、radius、{start、finish}。 取消保护
仍然让我害怕!无论如何,这就是我解决的问题。我还顽固地坚持了我原来方法的一些特点。
Manipulate[
Graphics[{
arcArrow[center, radius, {start, end}],
PointSize[Large], Blue, If[showCenter, Point[center]]},
PlotRange -> p, ImageSize -> 250],
{{start, \[Pi]/2}, -2 \[Pi], 2 \[Pi], ImageSize -> Small},
{{end, 0}, -2 \[Pi], 2 \[Pi], ImageSize -> Small},
{{radius, 1}, 1/2, 4, ImageSize -> Small},
{{center, {0, 0}}, {-p, -p}, {p, p}, Slider2D},
{showCenter, {True, False}},
Initialization :> {p = 3;
arcArrow[a_, r_, {start_, end_}] :=
{Circle[a, r, {start, end}],
Arrowheads[Medium],
Arrow[{a + r {Cos[end + If[end < start, .01, -.01]],
Sin[end + If[end < start, .01, -.01]]},
a + r {Cos[end], Sin[end]}}]} }]
I'd like to display a directed circular arc in Mathematica, using something as simple as Arrow
. The best I have been able to come up with is this example that nails an Arrow
onto one end of a circular arc. But I suspect there is a more direct way to achieve the same effect.
start=\[Pi];
Manipulate[
Graphics[{
Arrow[{{Cos[\[Theta] + If[\[Theta] < start, .01, -.01]],
Sin[\[Theta] + If[\[Theta] < start, .01, -.01]]},
{Cos[\[Theta]], Sin[\[Theta]]}}],
Circle[{0, 0}, 1, {start, \[Theta]}]},
PlotRange -> 2],
{{\[Theta], .7 start}, 0, 2 start}
]
Arrow
accepts BSplineCurves
and BezierCurves
but I can't get them to stay on a circular arc. Tube
accepts the formula for a curve in 3D but I can't figure out how to get it to work in 2D.
All suggestions are welcome. If your solution works for any 2D curve, all the better!
Epilogue:
I learned quite a bit from the suggestions:
Mark McClure showed that Arrow
itself can handle the demands when given a list of points.
yoda gave a fairly general solution using ParametricPlot.
I ended up finding belisarius' suggestions the most helpful. His approach was to work on minor variations of familiar graphical objects. In the end, I cautiously chose to define a new object, arcArrow
, that employs the parameters of Circle
: center, radius, {start,finish}. Unprotect
still scares me! Anyway, here's what I settled with. I also stubbornly held on to some features of my original approach.
Manipulate[
Graphics[{
arcArrow[center, radius, {start, end}],
PointSize[Large], Blue, If[showCenter, Point[center]]},
PlotRange -> p, ImageSize -> 250],
{{start, \[Pi]/2}, -2 \[Pi], 2 \[Pi], ImageSize -> Small},
{{end, 0}, -2 \[Pi], 2 \[Pi], ImageSize -> Small},
{{radius, 1}, 1/2, 4, ImageSize -> Small},
{{center, {0, 0}}, {-p, -p}, {p, p}, Slider2D},
{showCenter, {True, False}},
Initialization :> {p = 3;
arcArrow[a_, r_, {start_, end_}] :=
{Circle[a, r, {start, end}],
Arrowheads[Medium],
Arrow[{a + r {Cos[end + If[end < start, .01, -.01]],
Sin[end + If[end < start, .01, -.01]]},
a + r {Cos[end], Sin[end]}}]} }]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以向圆弧的终点添加箭头,如下所示:
这可能更容易控制,因为您可以以编程方式设置半径和弧长,只需替换最后的箭头即可。
您还应该看看关于 在边缘添加箭头的讨论一条曲线。那里有很多好的方法,也许比这个更好。我个人找到了西蒙对他自己的回答问题是我在我的“来自互联网的函数”集合中拥有的一个非常漂亮的小函数,并且不止一次地使用它来将箭头放置在继续绘图之外的图表上。
编辑
按照我上面定义的方式,它在行尾放置了一个箭头。例如,如果您绘制一条从 L 到 R 的线,则会将其放置在右侧和左侧。因此,在示例中,x 的正增加是逆时针方向的,因此箭头朝该方向。增加负方向将产生顺时针箭头。为了避免第二个绘图命令,我只是将列表中第三个函数中的 x 更改为 -x,这在金色曲线中产生了相同的效果。
更一般地说,您可以通过更改
Arrowheads
的输入来更改箭头方向,如下所示:箭头朝相反方向
两端都有箭头
倒箭头
You can also add an arrow to the end point of an arc like so:
This is probably much easier to control, as you can set the radius and arc length programmatically and just replace the arrows in the end.
You should also take a look at the discussion on adding arrows at the edges of a curve. There are a lot of good approaches there, perhaps better than this one. I personally found Simon's answer to his own question to be a pretty nifty little function that I have in my little 'functions from the internet' collection, and have used it more than once to place arrows on graphs that continue outside the plot.
EDIT
The way I've defined it above, it places an arrow at the end of the line. For e.g., if you plot a line from L to R, it places it on the right and left otherwise. So in the example, positive increase in x is counter-clockwise and hence the arrows in that direction. Increase in the negative dir will produce a clockwise arrow. To avoid a second plot command, I simply changed
x
to-x
in the third function in the list, which produced the same effect in the golden colored curve.More generally, you can change orientation of the arrows by changing the inputs to
Arrowheads
as follows:Arrows going the other way round
Arrows on both ends
Inverted arrowheads
使用圆形[]:
编辑
重新定义默认 Circle[ ] 行为:
Using Circle[ ]:
Edit
Redefining the default Circle[ ] behavior:
Arrow
接受任意长度的点列表。因此,也许是这样的。Arrow
accepts a list of points of arbitrary length. Thus, perhaps something like so.