• Stars
    star
    406
  • Rank 105,815 (Top 3 %)
  • Language
    JavaScript
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A book and examples on collision detection

Collision Detection

View the book, including interactive examples: jeffreythompson.org/collision-detection

UPDATE! This site has been getting lots of visits which is awesome. I've made some changes so it will look better on mobile devices, make navigation easier, and tried to look over everything for mistakes. If you have any problems or suggestions, please post an issue on the project repository. Thanks!

The collision of objects underlies most game experiences and user-interfaces. Baseball bats collide with balls, zombies bump into walls, and Mario lands on platforms and stomps turtles. Even something as simple as clicking a button (a rectangle) with your mouse (a point) is a collision.

This book explains the algorithms behind those collisions using basic shapes like circles, rectangles, and lines so you can implement them into your own projects.


WHAT'S COVERED HERE?

This book covers collisions between points, circles, rectangles, lines, polygons, and triangles. These examples are meant to be as readable and easily understood as possible. There are definitely faster, more efficient ways to detect these collisions, but this book is intended to be friendly and teach the principles with minimal math.

Each section includes a description of the collision algorithm and an interactive example built using processing.js.


WHAT'S NOT?

As with any book, there's a lot more useful material than could be covered here. Things that aren't discussed are mostly left out because the math gets too complicated. Three-dimensional space isn't touched on. Ellipses, which seem like they should be pretty easy, are actually very difficult.

If there's a specific collision not covered that would be helpful, please please submit an issue with a request or, better yet, submit a working example that you've built!


ISSUES?

If you find code that doesn't run correctly, an algorithm that isn't explained quite right, or a typo, please report them. Thanks for your help!


LICENSE

This book's entire contents, including the code examples and this text, is released under a Creative Commons Attribution, Non-Commercial, Share-Alike license. This means:

  1. You're welcome to use this book and the examples to make great stuff, but please cite this book somewhere in your project or its documentation.
  2. You can only use the book's text and/or code vertbatim for non-commercial projects. That means you can remix or make your own version of the book, and you can fork and create new libraries based on the code here, so long as they are not commercial projects (ie publishing a book with a publisher). I'm very happy to talk options if you have a paid gig and you'd like to use some of the materials.
  3. If you do make a project that forks or remixes this book or code-base, it must be released under this same license or a looser one. Pay it forward!

But you're free to use the ideas and code from this book inside your projects, so long as this is just a part of what you're working on. In other words: you're welcome to build a super cool game that relies on the code you've seen here, even if you're going to sell it!

If you have any questions about what you can and can't do with these examples, please get in touch.


WHAT YOU SHOULD ALREADY KNOW

This book's examples are written in Processing, a wrapper for the Java programming language. While you need only a little programming experience, you should understand how a basic Processing sketch is structured, how to use variables, how to draw shapes and get input from the mouse, and how if/else statements work. It may be helpful to understand using PVector objects to store positions, but we'll cover the basics if you haven't used them before.

At the end, we will talk about using collision in object-oriented code. Understanding object-oriented programming will not be required to use this book, but it will be helpful for using these topics in larger projects with lots of objects hitting each other.

More Repositories

1

DarkArduinoTheme

A dark theme for the Arduino IDE – no longer maintained :(
C++
827
star
2

PixelSorting

A set of experiments in pixel sorting using Processing
Processing
408
star
3

ProcessingTeachingSketches

Teaching sketches created in Processing (and Java)
Processing
121
star
4

Recipes

A super minimal recipe website built on Markdown
JavaScript
119
star
5

DarkProcessingTheme_3.0

A dark theme for Processing 3
81
star
6

CreativeProgramming1

An introductory course exploring code as a tool for creative making
JavaScript
67
star
7

CollisionDetectionFunctionsForProcessing

A set of simplified collision detection functions to Processing
Processing
59
star
8

CreativeProgramming2

An intermediate course in programming for the arts, focusing on zines, video, and live performance
JavaScript
57
star
9

Word2VecAndTsne

Scripts demo-ing how to train a Word2Vec model and reduce its vector space
Python
47
star
10

MaxMSP_TeachingSketches

Patches for teaching Max/MSP/Jitter
JavaScript
29
star
11

Pebble-Dataset

A machine learning dataset consisting of 5000 images of pebbles
19
star
12

DarkProcessingTheme_2.0

A dark theme for Processing 2.0
18
star
13

DesigningWithData

A course on data and design
JavaScript
16
star
14

PhysicalComputing

A course on art, electronics, and interactivity
13
star
15

Repo-As-Artwork

A list of artworks (and related projects) that are based in Github repos
11
star
16

ComputersOnLawAndOrder

Hardware/software and related files for a project commissioned by Rhizome.org (thanks!) gathering images of computers and computer use on the American television series "Law & Order".
Processing
11
star
17

DiehardCDROM

A re-creation of the original Diehard random number CD-ROM
C
10
star
18

MirrorTest

Teaching computers to recognize other computers, funded by Impakt.nl
Processing
10
star
19

MappingWirelessNetworks

Code, data, and (possibly) schematics for recording wireless network data around a city
Python
9
star
20

TCPDUMP

A month-long performance documenting every unique server from which my computer attempts to download a file.
Python
9
star
21

PythonTeachingExamples

Example scripts for learning Python
Python
9
star
22

EveryPossiblePhotograph

Source code for an installation that generates every possible photograph
Processing
8
star
23

TechnologyAndTheLandscape

A course exploring how technology has shaped the landscape and how we record it
Processing
7
star
24

TrainingOpenCV

A combination of tutorial and code (command line, Processing, and Python) for training OpenCV to detect objects
Processing
7
star
25

ChanceAndRandomness-OLD

A course exploring the creative potential of chance and randomness
Processing
6
star
26

TwitterBotTutorial

A fairly detailed tutorial on creating Twitter bots
Python
6
star
27

FM-Transmitter-Workshop

A workshop on building simple FM transmitters
5
star
28

EmptyApartments

Online curatorial project, made of 125k images of empty apartments
JavaScript
5
star
29

WebDesignExamples

Example files for teaching HTML, CSS, JavaScript, PHP, and other web technologies
CSS
5
star
30

ChanceAndRandomness

A one-day workshop and lecture on chance, randomness, entropy, and order in the arts • Transart Institute (May 2021) • Hartford Art School (Fall 2019)
Processing
5
star
31

InterestingThings

A running list of interesting projects, articles, and resources
4
star
32

NaNoGenMo

Experiments in algorithmically-generating a novel in a month
Python
4
star
33

RandomArtAssignmentBot

A Twitter bot that posts random art assignments
Python
4
star
34

PunchCardEncoding

FORTRAN punch-card encoding ported to Processing
Processing
4
star
35

InternetArchiveResidency

Working files and documentation for a residency with the Internet Archive, algorithmically-curating a series from the archive's collection
Python
4
star
36

PubJS

A simple, lightweight tool for embedding PDF publications
JavaScript
4
star
37

DarkProcessingTheme

A dark theme for the Processing IDE - a little easier on the eyes!
4
star
38

DesignResearchReadingList

A set of suggested examples of research in design, from project documentation to speculative ideas to writing about the process of design
3
star
39

Spaces

A conceptual art worm that changes the name of all your files and folders to whitespace
Python
3
star
40

DigitalFabrication

A course on digital fabrication for the arts
3
star
41

WhiteNoiseBoutique

An artwork/store for selling boutique white noise. Commisioned by Brighton Digital Festival.
Python
3
star
42

AnimatedGifWallpaper

Simple Java app to let you set animated GIFs as wallpaper (Mac only)
Processing
3
star
43

BotArtSchool

An art school run by bots (and an event for Abandon Normal Devices 2016)
Processing
2
star
44

Design2

Intermediate design course focusing on process, analog/digital, books, and screens
HTML
2
star
45

ParasiticComputer

A computer that feeds off of human body heat, commissioned by Digital Spring Festival
Processing
2
star
46

ArduinoTeachingSketches

Arduino
2
star
47

WouldYouRatherBot

A Twitter bot that asks random "would you rather" questions
Python
2
star
48

RedactionBot

Python
2
star
49

ClusterTumblrTheme

A decidedly effed-up Tumblr theme
2
star
50

EagleCAD_Tutorials

A set of tutorials for learning EagleCAD and circuit design
2
star
51

RandomChordBot

A Twitter bot that posts random guitar chords
Python
2
star
52

FAQBot

A bot that publishes randomized FAQs.
HTML
2
star
53

Design3

Advanced course focusing on long-form design research
2
star
54

VibrationInterface

A vibration interface for the Arduino; created with generous assistance from Harvestworks' Cultural Innovation Fund program
Arduino
2
star
55

OneMillionRandomDigits

Sculpture visualizing Rand Corp's "One Million Random Digits"
Processing
2
star
56

Interp

Code and related files for a commission from Turbulence.org
JavaScript
2
star
57

SpamNovel_NaNoGenMo2014

A novel generated using spam comments by 34,914 authors on my blog; created for NaNoGenMo 2014
Python
2
star
58

LasercutterMaterialsDatabase

A customizable site for lasercutter materials
JavaScript
1
star
59

GithubTutorial

Tutorial repo for CP2
Processing
1
star
60

ICPinStraightener

A tool for straightening the pins on integrated circuits
1
star
61

YouHaveBeenBlinded

A non-visual, haptic electronic game developed in collaboration with Alex Myers
Eagle
1
star
62

ViewSource

Files and resources for a workshop digging into the hidden texts of the web
1
star
63

EveryRadioStation

Installation of 95 FM radios, one for each station in the FM band
C++
1
star
64

CheckoutFormGenerator

Python script for generating checkout sheets and equipment hang tags
Python
1
star
65

HapticVibrationShield

Haptic vibration shield for Arduino: 4 vibration motors and the TI DRV2603 haptic driver IC
Prolog
1
star
66

GamesPlusPlusBadge

Electronic game badges created for Games++ (Nov 2013), created in collaboration with Alex Myers (www.alexmyers.info)
Arduino
1
star
67

SmartphoneTripodKickstand

A little kickstand for a cheap smartphone tripod mount
1
star
68

Cave

A low-res sonic game for tablet; created with generous assistance from Harvestworks' Cultural Innovation Fund program.
Processing
1
star
69

DungeonBot

I am a wanderer, trapped in an infinite dungeon.
Python
1
star
70

CatCapture

Move your body into the shape of a cat. Made for Games++ 2015.
Processing
1
star
71

iPhoneStethoscopeAttachment

An attachment for the iPhone 4/5 for recording from a stethoscope
1
star