Circle line-segment collision detection algorithm?

前端 未结 28 1337
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 06:38

I have a line from A to B and a circle positioned at C with the radius R.

\"Image\"

What is a good alg

28条回答
  •  粉色の甜心
    2020-11-22 06:59

    Here is good solution in JavaScript (with all required mathematics and live illustration) https://bl.ocks.org/milkbread/11000965

    Though is_on function in that solution needs modifications:

    function is_on(a, b, c) {
        return Math.abs(distance(a,c) + distance(c,b) - distance(a,b))<0.000001;
    }

提交回复
热议问题