2D Soft Body Collisions with Bisector Rays

QuarkPhysics resolves 2D soft body collisions with a hybrid solution based on bisector rays, point and edge tests, optimized for real-time performance and with an extension for Godot.

domingo, 17 de agosto de 2025 • 4 min read • Q2BSTUDIO Team

Artificial-Intelligence-

This article clearly presents how QuarkPhysics handles 2D soft body collisions using a practical approach based on bisector rays.

About QuarkPhysics: QuarkPhysics is an open-source 2D physics engine focused on multi-dynamics that supports both rigid bodies and advanced soft body dynamics. It is designed to offer stability and performance in 2D games and already has a native extension for the Godot engine.

Initial challenge: in 2D, geometric constraints are stricter than in 3D, so common techniques from 3D engines do not adapt well. Extending SAT, the separating axis theorem, seemed logical for consistency with rigid body detection, but in soft bodies it caused performance issues and cases that SAT does not handle well, such as non-convex polygons and vertices that change every frame.

Alternatives such as GJK and Minkowski difference proved too computationally expensive for real-time 2D use, so it was necessary to experiment with a hybrid solution that balances cost and robustness.

Complex polygons: QuarkPhysics aims to support polygons with many deformable points each frame, including concave and nested shapes. This requires a method that detects real collisions and is stable when resolving deep penetrations.

Point-in-polygon tests: the point-in-polygon test is fast and useful as an initial detection phase, but by itself it fails in many real scenarios. Two boxes with opposing vertices or concave polygons can penetrate each other without any vertex being inside the other, so intersections between edges must also be detected.

Real detection cases: in practice, there are basically two scenarios to cover. One where a vertex of polygon A ends up inside polygon B, and another where the edges of A intersect the edges of B. QuarkPhysics' strategy uses point-in-polygon for the first case and edge intersection tests for the second.

Collision resolution: detecting the collision is only half the problem. Resolving it correctly in highly concave shapes or when a soft body ends up completely inside another requires avoiding solutions that cause an object to be absorbed or create instability in the simulation.

Bisector rays for resolution: the key proposal is to generate from each vertex of a polygon a bisector ray that is the bisector of the angle formed by the adjacent edges. That ray is projected until it hits the boundaries of the polygon itself and is calculated once per frame. In practice, reduced ray lengths are used for greater stability.

Stable escape method: when a vertex collides or edges intersect, the affected vertex is identified and the nearest edge of the target polygon is sought. The bisector ray of the colliding vertex is tested against those edges, and the first edge it intersects whose normal vector points in the same direction as the bisector is taken as the escape path. This check of the normal direction avoids pushing vertices inward in concave shapes and reduces swallowed object scenarios.

Phase combination: the pipeline combines point-in-polygon, edge intersection, and bisector rays to cover edge cases and maintain performance. Each phase solves a specific set of problems, reducing the need for costly polygon decomposition and avoiding ghost collisions.

Soft body vs. rigid body collisions: for mixed interactions, a hybrid approach is applied. First, the soft body's vertices are expelled from the rigid polygon using point-in-polygon tests, and then bisector rays from the rigid body's vertices are used to detect and resolve collisions with the soft body's edges. This technique proves economical and consistent when a rigid body is convex and the soft body is complex.

Performance and quality: the combination of these techniques in QuarkPhysics offers greater stability and fewer error cases than traditional methods applied directly, as well as adequate performance for real-time simulations with complex geometries.

Conclusion: the bisector ray approach, complemented by point-in-polygon tests and edge intersection, is a practical and efficient solution for 2D soft body collisions that balances computational cost and robustness, and facilitates integration with multi-dynamic simulations.

About Q2BSTUDIO: Q2BSTUDIO is a software development company dedicated to creating custom applications and custom software for clients who need personalized solutions. We are specialists in artificial intelligence and AI for businesses, AI agents, cybersecurity, and AWS and Azure cloud services. We offer business intelligence services and alternatives such as Power BI for advanced visualization and analysis. Our competencies cover custom application development, integration of artificial intelligence models, design of secure architectures, and deployment on AWS and Azure cloud services to ensure scalability and compliance.

Why choose us: Q2BSTUDIO combines technical expertise with a business focus to deliver custom software that improves processes, increases automation, and adds value through applied artificial intelligence, intelligent AI agents, and business intelligence solutions. We also provide cybersecurity audits, hardening, and recovery plans, and offer support for migrations and deployments on AWS and Azure cloud services.

Featured services: custom applications, custom software, artificial intelligence solutions for businesses, AI agents, Power BI implementations, business intelligence services, comprehensive cybersecurity, and AWS and Azure cloud services. If you are looking for a technical partner that covers everything from prototype to production and monitoring, Q2BSTUDIO offers consulting, development, and continuous operation.

Contact us to evaluate how we can turn an idea into a productive and secure solution leveraging best practices in artificial intelligence, cybersecurity, custom applications, and AWS and Azure cloud services.

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.