使用 mathematica 可视化几何难题
我正在尝试找出一种方法来沿着具有顶点 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}}]]
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}}]]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
怎么样:
和
How about something like:
and