Hey guys,
is there a circle object like line2d or point2d available?
I need to detect, if a line intersects with a 2d circle. Any ideas?
MfG
Scarabol
Circle object in Irrlicht?
Circle object in Irrlicht?
Irrlicht 1.7.2
Eclipse
Boost
Eclipse
Boost
You can use line2d::getClosestPoint and give it the center of your circle. Then subtract the result from the center and you get a vector from the center to the closest point on the line. Then you can check if that lines length is shorter than the circle radius in which case it collides.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
If you copy getClosestPoint from line2d.h and kick out out the 't' checks then it will no longer just return the closest point on the line-segment, but the closest point on the (infinite) line (let's call it X). X, the circle-center and each of the collision points form 2 right-angled triangles. You know the distance of X to the circle-center and the distance of the center to the collision points (the circle radius). So with A²+B²=C² you can get the length of the 3rd side of that triangle. That's the length you will have to add to X toward both directions of the line to get the collision-points.
But maybe take a look on the net, could be there's easier solutions for that (I was too lazy to google that now).
But maybe take a look on the net, could be there's easier solutions for that (I was too lazy to google that now).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm