Unit tests and Line vs Circle | Coding a 2D Physics Engine in Java #6 @GamesWithGabe
Unit tests and Line vs Circle | Coding a 2D Physics Engine in Java #6  @GamesWithGabe
Uploaded July 2020 | Updated September 2026, 2 weeks ago
Join the Discord: discord.gg/4tHeAkxNg7

In this episode I go over how to tell if a line segment is intersecting with a circle. We use some fancy math to project the vector from the line's beginning to the center of the circle onto the line segment, then we check the length of that against the length of the line. If the length of the circle to beginning of the line segment is less than the lenght of the line segment and greater than zero, then the line is intersecting. I also go over how to create unit tests for all these functions. So, we integrate JUnit, then set up a simple test class, and finally add the test class to our build configuration so that unit tests are run before the program is started every time. This is a good way to ensure that your code doesn't break if you change things in the future.

Source Code: github.com/codingminecraft/MarioYoutube/tree/4651849df0c9ae2ce94c5110ff3359f2a94c53bc

0:00 Intro
0:44 Math behind line vs circle
6:11 Coding line vs circle
10:51 Setting up unit tests

---------------------------------------------------------------------
Website: ambrosiogabe.github.io
Github: github.com/ambrosiogabe

Here are some books I recommend if you want to learn about game engine development more thoroughly. I do not profit off any of these sales, these are just some books that have helped me out :)

My Recommended Game Engine Books:
Game Engine Architecture: gameenginebook.com
Game Physics Cookbook (Read this before the next physics book): amazon.com/Game-Physics-Cookbook-Gabor-Szauer/dp/1787123669
Game Physics (Ian Millington): amazon.com/Game-Physics-Engine-Development-Commercial-Grade/dp/0123819768
Game Programming Patterns (Free): gameprogrammingpatterns.com

My Recommended Beginning Game Programming Books:
JavaScript Game Design: apress.com/gp/book/9781430247166

My Recommended Java Books:
Data Structures/Algorithms: amazon.com/Data-Structures-Algorithms-Java-6th-ebook/dp/B00JDRQF8C
LWJGL (Free, but I haven't read this thoroughly): lwjglgamedev.gitbooks.io/3d-game-development-with-lwjgl/content

Outro Music: bensound.com/royalty-free-music
Unit tests and Line vs Circle | Coding a 2D Physics Engine in Java #6Event Listeners | Coding Geometry Dash in Java #2Coding a Physics Engine | Cocoa Engine Devlog #7Font Rendering | Coding a 2D Game Engine in Java #41Setting up the Window with LWJGL | Coding a 2D Game Engine in Java #1References | C++ For Java Devs Ep. 10Drag N Drop Level Editor | Coding a 2D Game Engine in Java #23Even More Bug Fixing | Coding a 2D Game Engine in Java #44Broadphase Collision Detection | Coding Geometry Dash in Java #23Dirty Flags in Rendering | Coding a 2D Game Engine in Java #15Circle vs Shape Collision Detection | Coding a 2D Physics Engine in Java #10Converting Screen Coords to World Coords | Coding a 2D Game Engine in Java #22
GamesWithGabe |

Unit tests and Line vs Circle | Coding a 2D Physics Engine in Java #6

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER