使用 mathematica 可视化几何难题

发布于 2024-09-28 04:48:46 字数 1293 浏览 0 评论 0原文

我正在尝试找出一种方法来沿着具有顶点 A、B 和 C 的等边三角形的边彼此独立地移动两个点 X 和 Y。还需要考虑一些碰撞规则:

(1) 如果 X 位于顶点(例如顶点 A),则 Y 不能位于 A 上或与其相邻的边上。即,Y 只能位于顶点 B 或 C 或边 BC 上。

(2)如果X在一条边上,比如说AB,那么Y不能在A上,也不能在B上,也不能在与A和B相邻的任何边上。即,Y必须在顶点C上

我已经弄清楚如何移动使用一对滑块沿着三角形的两个点,但我不知道如何实现碰撞规则。我尝试使用滑块的排除选项,但结果不是我所期望的。我更喜欢沿着三角形拖动点而不是使用滑块,所以如果有人知道如何做到这一点,那将会很有帮助。理想情况下,我能够 将两个点从一个顶点移动到任一边,而不是停在其中一个边上。到目前为止,这是我的代码。

MyTriangle[t_] :=
分段[{{{-1, 0} + (t/100) {1, Sqrt[3]},
100> t >= 0}, {{0, Sqrt[3]} + (t/100 - 1) {1, -Sqrt[3]},
200> t >= 100},
{{1, 0} + (t/100 - 2) {-2, 0}, 300 >= t >= 0}}]
排除[x_] := \[分段] {
{范围[0, 99]~连接~范围[201, 299], x == 0},
{范围[0, 199], x == 100},
{范围[101, 299], x == 200},
{范围[0, 199]~加入~范围[201, 299], 0 < x < 100},
{范围[1, 299], 100 < x < 200},
{范围[0, 99]~加入~范围[101, 299], 200 < x < 300}
}
{动态[t],动态[x]}
{滑块[Dynamic[t], {0, 299, 1}, 排除 ->动态[排除[x]]],动态[t]}
{滑块[Dynamic[x], {0, 299, 1}, 排除 ->动态[排除[t]]],动态[x]}
动态[图形[{PointSize[大],点[MyTriangle[t]], 点[MyTriangle[x]],
行[{{-1, 0}, {1, 0}, {0, Sqrt[3]}, {-1, 0}}]},
绘图范围 -> {{-1.2, 4.2}, {-.2, 2}}]]

Mathematica 图形

I am trying to figure out a way to move two points, X and Y, independently of one another along the edges of an equilateral triangle with vertices A, B, and C. There are also some collision rules that need to be taken into account:

(1) If X is at a vertex, say vertex A, then Y cannot be on A or on the edges adjacent to it. i.e., Y can only be on vertices B or C or the edge BC.

(2) If X is on an edge, say AB, then Y cannot be on A, nor B, nor any of the edges adjacent to A and B. i.e., Y must be on vertex C

I have figured out how to move the two points along the triangle using a pair of sliders, but I can't figure out how to implement the collision rules. I tried using the Exclusions option for Slider but the results are not what I expect. I would prefer to drag the points along the triangle rather than using sliders, so if someone knows how to do that instead it would be helpful. Ideally, I would be able to
move the two points from a vertex to either one of the edges instead of coming to a stop at one of them. Here is my code so far.

MyTriangle[t_] :=
Piecewise[{{{-1, 0} + (t/100) {1, Sqrt[3]},
100 > t >= 0}, {{0, Sqrt[3]} + (t/100 - 1) {1, -Sqrt[3]},
200 > t >= 100},
{{1, 0} + (t/100 - 2) {-2, 0}, 300 >= t >= 0}}]
excluded[x_] := \[Piecewise] {
{Range[0, 99]~Join~Range[201, 299], x == 0},
{Range[0, 199], x == 100},
{Range[101, 299], x == 200},
{Range[0, 199]~Join~Range[201, 299], 0 < x < 100},
{Range[1, 299], 100 < x < 200},
{Range[0, 99]~Join~Range[101, 299], 200 < x < 300}
}
{Dynamic[t], Dynamic[x]}
{Slider[Dynamic[t], {0, 299, 1}, Exclusions -> Dynamic[excluded[x]]], Dynamic[t]}
{Slider[Dynamic[x], {0, 299, 1}, Exclusions -> Dynamic[excluded[t]]], Dynamic[x]}
Dynamic[Graphics[{PointSize[Large], Point[MyTriangle[t]],
Point[MyTriangle[x]],
Line[{{-1, 0}, {1, 0}, {0, Sqrt[3]}, {-1, 0}}]},
PlotRange -> {{-1.2, 4.2}, {-.2, 2}}]]

Mathematica graphics

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

究竟谁懂我的在乎 2024-10-05 04:48:47

怎么样:

MyTriangle[t_]:=Piecewise[{
    {{-1,0}+t {1,Sqrt[3]},1>t>=0},
    {{0,Sqrt[3]}+(t-1) {1,-Sqrt[3]},2>t>=1},
    {{1,0}+(t-2) {-2,0},3>=t>=0},{0,True}}]

Column[{
  {Slider[Dynamic[x], {0, 3, .01}], Dynamic[x]},
  {Slider[Dynamic[y], {0, 3, .01}], Dynamic[y]},
  Dynamic[x = Mod[x, 3]; Which[
   x==0.,Which[0.<=y<1.,y=1.,2.<y<=3.,y=2.],0.<x<1.,y=2.,
   x==1.,Which[1.<=y<2.,y=2.,0.<y<=1.,y=0.],1.<x<2.,y=0.,
   x==2.,Which[2.<=y<3.,y=0.,1.<y<=2.,y=1.],2.<x<3.,y=1.];
   Graphics[{PointSize[Large], Point[MyTriangle /@ {x, y}], 
     Line[{{-1, 0}, {1, 0}, {0, Sqrt[3]}, {-1, 0}}]}]]}]

How about something like:

MyTriangle[t_]:=Piecewise[{
    {{-1,0}+t {1,Sqrt[3]},1>t>=0},
    {{0,Sqrt[3]}+(t-1) {1,-Sqrt[3]},2>t>=1},
    {{1,0}+(t-2) {-2,0},3>=t>=0},{0,True}}]

and

Column[{
  {Slider[Dynamic[x], {0, 3, .01}], Dynamic[x]},
  {Slider[Dynamic[y], {0, 3, .01}], Dynamic[y]},
  Dynamic[x = Mod[x, 3]; Which[
   x==0.,Which[0.<=y<1.,y=1.,2.<y<=3.,y=2.],0.<x<1.,y=2.,
   x==1.,Which[1.<=y<2.,y=2.,0.<y<=1.,y=0.],1.<x<2.,y=0.,
   x==2.,Which[2.<=y<3.,y=0.,1.<y<=2.,y=1.],2.<x<3.,y=1.];
   Graphics[{PointSize[Large], Point[MyTriangle /@ {x, y}], 
     Line[{{-1, 0}, {1, 0}, {0, Sqrt[3]}, {-1, 0}}]}]]}]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文