Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

When handling collision detection / response and you need a Vector class, do you need to create that class yourself or is there a java class you can use?

A vector class should have methods like: subtract(Vector v), normalize(), dotProduct(Vector v), ...

At the moment it seems logical to use classes like java.awt.Rectangle and java.awt.Polygon to calculate collisions. Would I be right to use these classes for this purpose?

My question is not about how to implement collision detection, I know how that works. However I'm wondering what would be a correct and clean way to implement it in java since I'm fairly new to the language and to application development in general.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

There is no built in math Vector class. You'll have to implement your own or use a library like JScience - its project page is here.

share|improve this answer
add comment

You could implement Vectors in Java using Vecmath. Its documentation is located here.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.