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

preview_player
Показать описание

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.

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

---------------------------------------------------------------------

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:

My Recommended Beginning Game Programming Books:

My Recommended Java Books:

Рекомендации по теме
Комментарии
Автор

well there's a small error

A.B=|A| |B| cos (ø)
and B.B = |B|² cos(0) not cos(ø)
so u cant cancel it at 4:35

prashanthkumar
Автор

You got some pretty high quality tutorials. I really hope this channel will gain more traction. Keep it up!

Sculman
Автор

I think your point on line test will miss another edge case where the line is very close to vertical but not quite, say something like (0, 0) to (min_float, 1000). In your point on line function it would probably be better to check if m is infinity and then handle that case instead of checking if dx is 0

NatHsu
Автор

Great video! I just want to point out that (A · B)/(B · B) is ||A|| Cosθ(between A and B)/||B|| Cosθ(between B and B which is 1). :)

SyloRiyami
Автор

I got stuck at this part because my project has neither a test folder nor Gradle.. I'm using a much more recent version of intellij and didn't create my project as a gradle project so could that be the reason?

chingoputoh
Автор

Hi ! and thank you for this serie ! I have a question: In the lineAndCircle() method, you wrote "ab = Isn't it equal to "Vector2f(line.getStart())" ?? I'm trying to do that in javascript and I created a class "Line2D" that takes two vectors for start and end arguments. (I hope my english is not too bad :p). Thanks again !
Edit: It's not, I think i understood.

alanvandenbosch
Автор

what exactly is dot method in vector? sorry I'm confused

carljeffersondelfin
welcome to shbcf.ru