在 Mathematica 中计算笛卡尔坐标系中的距离
分析屏幕上的眼球运动,我将原点设置为屏幕的左下角 (当时很难修改)。
尝试计算某些点与屏幕中心之间的距离,我使用下面显示的简单公式。 问题是,在条件语句中使用它会变得很难看。
Sqrt[
(
(fixationX - centerX)^2 + (fixationY - centerY)^2
)
]
有没有办法自定义 Norm 来计算点之间的距离而不是点与原点之间的距离?
或者就我而言,将原点设置为当前坐标系的“中心”?
Analyzing Eye-movements on a screen, I set my origin to the bottom left corner of it
(Hard to modify at that point).
Trying to compute distance between some points and the center of the screen I use the simple formula displayed below.
Problem is that using this in conditional statement, it gets ugly.
Sqrt[
(
(fixationX - centerX)^2 + (fixationY - centerY)^2
)
]
Is there a way to customize Norm to compute distance between points and not between a point and the origin ?
Or in my case, set the origin to be at the "center" of the current coordinate system ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Simon 方法的一个细微变化是在函数中使用默认值,而不是全局变量 (
$Center
)。假设您的默认原点是 (5, 5),那么:
请注意使用
_:{5, 5}
来定义默认值。现在你可以这样做:
或者暂时使用不同的中心:
对于这个简单的函数,你可以在第二种情况下使用
EuclideanDistance
,但我希望你能看到这个方法的实用性是定义myNorm
更复杂。此方法的缺点是您无法轻松更改默认中心。
另一种允许人们轻松更改默认中心的变体是使用
Options
:语法是:
更改默认中心:
A slight variation of Simon's method is to use a default value in the function, rather than a global variable (
$Center
).Suppose your default origin is (5, 5), then:
Notice the use of
_:{5, 5}
to define the default value.Now you can do:
Or temporarily use a different the center with:
For this simple function, you could use
EuclideanDistance
in the second case instead, but I hope you can see the utility of this method were the definition ofmyNorm
more complex.The downside to this method is that you cannot easily change the default center.
Another variation that does allow one to easily change the default center, but is more verbose, is to use
Options
:Syntax is:
Changing the default center:
您可以只使用
EuclideanDistance
或者定义一个
$Center
和一个新的CNorm
,例如Can you just use
EuclideanDistance
Or define a
$Center
and a newCNorm
, e.g.