Vec1 = Circle centre, Vec2 = mousepos, find the po

2019-09-18 18:30发布

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'.

I want 'the point'(vec2d_X) on the circle between the 'centre of the clock' (vec2d_1) and the 'mouse position'(vec2d_2).

See also this follow up question:
Determine rotation direction /toward/ variable point on a circle

EDIT>>>>>>

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

1条回答
女痞
2楼-- · 2019-09-18 19:33

radius_vector = mouse_position - circle_center

normalized_vector = radius_vector * circle_radius / radius_vector.length()

circle_point = circle_center + normalized_vector

Clarification:

vector.length=sqrt(vector.x*vector.x+vector.y*vector.y)

查看更多
登录 后发表回答