Vec1 = 圆心,Vec2 = mousepos,在 Vec1, Vec2 之间找到圆上的点 [英] Vec1 = Circle centre, Vec2 = mousepos, find the point on the circle between Vec1, Vec2
问题描述
我有两个向量:一个在圆心,另一个在鼠标位置.我想在圆上找到两个向量之间的点.
I have two vectors: one is in the centre of a circle, another is at the mouse position. I want to find the point on the circle that is between the two vectors.
我特别想要圆心+直径的答案,而不是三角函数.所以,圆心+圆直径(方向)鼠标位置.
I specifically want the answer in terms of circle centre + diameter, not trigonometry. So, Circle centre + circle diameter (in the direction of) the mouse position.
如果有帮助,想想时钟.我需要手"指向的数字"的向量坐标.手总是指向变量向量鼠标位置".
If it helps, think of a clock. I need the vector coordinance of the 'number' the 'hand' is pointing to. The hand is always pointing toward the variable vector 'mouse position'.
我想要点"(vec2d_X) 在时钟中心"(vec2d_1) 和鼠标位置"(vec2d_2) 之间的圆圈.
I want 'the point'(vec2d_X) on the circle between the 'centre of the clock' (vec2d_1) and the 'mouse position'(vec2d_2).
另请参阅此后续问题:
确定旋转方向/toward/圆上的可变点
See also this follow up question:
Determine rotation direction /toward/ variable point on a circle
编辑>>>>>>
使用trig 会更快吗?
Is using trig faster?
#Python
def circlepoint_trig(vertex, mousepos, circlepoint):
angle = math.atan2(mousepos[1] - vertex[1], mousepos[0] - vertex[0])
myx = 80 * math.cos(angle) #80 is length of clock 'hand'
myy = 80 * math.sin(angle) #80 is length of clock 'hand'
circlepoint = vec2d(myx,myy) + vertex
return circlepoint
推荐答案
radius_vector = mouse_position - circle_center
normalized_vector = radius_vector * circle_radius/radius_vector.length()
circle_point = circle_center + normalized_vector
澄清:
vector.length=sqrt(vector.x*vector.x+vector.y*vector.y)
这篇关于Vec1 = 圆心,Vec2 = mousepos,在 Vec1, Vec2 之间找到圆上的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!