Search ProofOfProgress Blog


Wednesday, April 27, 2011

Capsule Line Collision Source Code

Download Source: ****HERE****
Here is a demo of some capsule-line collision I whipped up.
One thing I am proud of is I made a formula that finds the intersection of
a circle using the function graph of a circle.

Basically, if you take a ray and want to know where that ray intersects the circle:

The ray pointing towards the circle:
rP = ray point.
rV = ray vector.

The circle:
CP = center point of circle.
cr = radius of circle.

[1]: Take negative receprocal of rV to get perpendicular vector pV.
[2]: combine pV with CP to get a perpendicular at center of circle.
[3]: set rays [rP rV] and [CP pV] equal to each other and find
intersection using point-normal form.
Call this intersection RC
[4]: Find distance: intersection to circle center. Call this distance DS.
[5]: Divide DS by the cr to get a value from 0 to 1.
[6]: Input this 0to1 value into the function graph of a circle:
[7]: Take the y-height output and scale it up by the radius (cr) of the circle.
Call this value SKA.
[8]: Flip the sign of normalized rV. Translate it to the intersection point RC.
[9]: Intersection on circle = RC+(SKA*normalized_rV);

1 comment:

  1. Lovely! Any chance you can fix the download link? I'd love to see the actual code too.