找到两点之间的一点

发布于 2024-08-11 00:23:12 字数 87 浏览 8 评论 0原文

我在屏幕上有两个同心圆,我希望当用户在较大圆的外侧拖动手指时,内侧的圆可以四处移动。这意味着我有两个点,大圆的中心和用户触摸的点。如何计算小圆的中心应该在哪里?

I two concentric circles on the screen and I want the circle on the inside to move around while the user drags their finger around the outside of the larger circle. This means that I have two point, center of the larger circle and the point at which the user touched. How do I calculate where the center of the smaller circle should be?

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

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

发布评论

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

评论(2

猛虎独行 2024-08-18 00:23:12

好吧,如果你画的是一个人的眼睛,那就完全是另一回事了。

如果我们从以下值开始

  • re:眼睛半径
  • rp:瞳孔半径
  • p1 = (x1, y1):的坐标
    眼睛中心
  • p2 = (x2, y2):坐标
    用户触摸
  • v1 = [x3; y3]:p1p2 之间的方向向量。
    • x3 = (x1 - x2)
    • y3 = (y1 - y2)
  • l = sqrt((x3)^2 + (y3)^2 )v1的长度

然后执行以下步骤

  1. 检查用户是否触摸在眼睛中部的re-rp范围内(即l <(re - rp)),如果他/她在p2处绘制瞳孔并且不再做任何事情。
  2. 否则,在 x 坐标 (re - rp) * x3 / l + x1y 坐标 (re - rp) 处绘制瞳孔* y3 / l + y1

如果您有不止一只眼睛,只需对其他眼睛重复上述步骤即可。

我当然希望你明白我的意思,如果你不直接问。

Ok, if you're drawing a persons eyes it is a completely different matter.

If we start with the following values

  • re: the radius of the eye
  • rp: the radius of the pupil
  • p1 = (x1, y1): the coordinates of
    the center of the eye
  • p2 = (x2, y2): the coordinates of
    the users touch
  • v1 = [x3; y3]: the direction vector between p1 and p2.
    • x3 = (x1 - x2)
    • y3 = (y1 - y2)
  • l = sqrt((x3)^2 + (y3)^2): the length of v1

Then do the following steps

  1. Check if the user is touching within re - rp of the middle of the eye (i.e. l < (re - rp)), it he/she is draw the pupil at p2 and do no more.
  2. Otherwise draw the pupil at x coordinate (re - rp) * x3 / l + x1 and y coordinate (re - rp) * y3 / l + y1

If you have more than one eye, just repeat the steps for the other ones.

I certainly hope you understand what I mean by this, if you don't just ask away.

彩扇题诗 2024-08-18 00:23:12

我不太明白你的要求,请尝试更具体一些。内圆的中心应该在哪里?

它应该位于外圆中心和用户触摸点之间的中点吗?

在这种情况下,事情就非常简单了。找到线的中间非常简单。如果您有坐标 (x1, y1)(x2, y2)。中点的 x 坐标为 x1 + (x2 - x1) / 2,y 坐标为 y1 + (y2 - y1) / 2

(我忽略了你提到的同心圆,因为这似乎不是你想要的。)

I don't really get what you're asking for, try being more specific. Where is the center of the inner circle supposed to be?

Is it supposed to be at the midpoint between the outer circle's center and the point where the user touched?

In that case it is pretty simple. Finding the middle of the line is pretty simple. If you have the coordinates (x1, y1) and (x2, y2). The x coordinate of the midpoint is x1 + (x2 - x1) / 2 and the y coordinate is y1 + (y2 - y1) / 2.

(I'm ignoring your mention of concentric circles since it didn't seem like that was what you were looking for.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文