找到两点之间的一点
我在屏幕上有两个同心圆,我希望当用户在较大圆的外侧拖动手指时,内侧的圆可以四处移动。这意味着我有两个点,大圆的中心和用户触摸的点。如何计算小圆的中心应该在哪里?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,如果你画的是一个人的眼睛,那就完全是另一回事了。
如果我们从以下值开始
re
:眼睛半径rp
:瞳孔半径p1 = (x1, y1)
:的坐标眼睛中心
p2 = (x2, y2)
:坐标用户触摸
p1
和p2
之间的方向向量。x3 = (x1 - x2)
y3 = (y1 - y2)
l = sqrt((x3)^2 + (y3)^2 )
:v1
的长度然后执行以下步骤
re-rp
范围内(即l <(re - rp)
),如果他/她在p2
处绘制瞳孔并且不再做任何事情。x
坐标(re - rp) * x3 / l + x1
和y
坐标(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 eyerp
: the radius of the pupilp1 = (x1, y1)
: the coordinates ofthe center of the eye
p2 = (x2, y2)
: the coordinates ofthe users touch
v1 = [x3; y3]
: the direction vector betweenp1
andp2
.x3 = (x1 - x2)
y3 = (y1 - y2)
l = sqrt((x3)^2 + (y3)^2)
: the length ofv1
Then do the following steps
re - rp
of the middle of the eye (i.e.l < (re - rp)
), it he/she is draw the pupil atp2
and do no more.x
coordinate(re - rp) * x3 / l + x1
andy
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.
我不太明白你的要求,请尝试更具体一些。内圆的中心应该在哪里?
它应该位于外圆中心和用户触摸点之间的中点吗?
在这种情况下,事情就非常简单了。找到线的中间非常简单。如果您有坐标
(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 isx1 + (x2 - x1) / 2
and the y coordinate isy1 + (y2 - y1) / 2
.(I'm ignoring your mention of concentric circles since it didn't seem like that was what you were looking for.)