For my CC23 entry, I need to check if a triangle is intersecting the rectangle that will be the player's hitbox...
I'm trying to find a relatively simple algorithm to handle this, given the coordinates of all the vertices.

The wikipedia article about line-line intersection looks like it would be helpful, but it is pretty complicated looking and confusing

And I'm also not sure how much sense this makes to me either...

Maybe I'm dumb, but is there an easier way to do this?
Quote:

To find out if Point B (Purple) overlaps the rectangle (Collision), use this formula if format = (x,y):
(a,b) = Point B
(x,y) = Green Point
(v,w) = Blue Point

Code:
```bool overlap == false; if ((a<=x && b<=y) && (a>=v && b>=w)) {     overlap == true; }```

This will set bool overlap to true if the point overlaps, else, it will be false.

In TI-BASIC, it would be this:

Code:
```0→O If (A≤X and B≤Y) and (A≥V and B≥W) Then 1→O End```

I believe this is all you are asking for (please tell me if I'm confusing you; I tried to be clear)
calclover2514 wrote:

Code:
```0→O If (A≤X and B≤Y) and (A≥V and B≥W) Then 1→O End```

I believe this is all you are asking for (please tell me if I'm confusing you; I tried to be clear)

That makes sense, and it would be exactly what I need if i just wanted to see if a point was inside the other shape, but I need to see if any part of the rectangle is inside the triangle... i may have thought of a way to do it, but I am not sure
If there are restrictions on the sizes and orientations of the shapes, there are lots of corners that can be cut with collision detection.
Runer112 wrote:
If there are restrictions on the sizes and orientations of the shapes, there are lots of corners that can be cut with collision detection.

I am wanting to check if the red box intersects the blue triangles ever. The size of the triangles can change, and the red box will only ever be either 8x16, or 8x8

I was just about to add this gif to my previous post, but now it is actually useful
Alright, so in this case, I think the logic can be greatly cut down to three relatively simple checks that must all pass:
1. The rectangle and the rectangle bounding the triangle intersect (https://stackoverflow.com/a/306332/3447746)
2. The bottom-posterior (bottom-right if vision triangle is aiming right, bottom-left if vision triangle is aiming left) corner of the rectangle, (x₀, y₀), is below the upper edge of the triangle, formed by points (x₁, y₁) and (x₂, y₂): (y₀ - y₁)(x₂ - x₁) < (x₀ - x₁)(y₂ - y₁) (http://mathworld.wolfram.com/Two-PointForm.html)
3. The top-posterior corner of the rectangle, (x₀, y₀), is above the lower edge of the triangle, formed by points (x₁, y₁) and (x₂, y₂) (same equation as before, just flip the comparison)
This is all untested, but it seems like it should work.
Runer112 wrote:
Alright, so in this case, I think the logic can be greatly cut down to three relatively simple checks that must all pass:
1. The rectangle and the rectangle bounding the triangle intersect (https://stackoverflow.com/a/306332/3447746)
2. The bottom-posterior (bottom-right if vision triangle is aiming right, bottom-left if vision triangle is aiming left) corner of the rectangle, (x₀, y₀), is below the upper edge of the triangle, formed by points (x₁, y₁) and (x₂, y₂): (y₀ - y₁)(x₂ - x₁) < (x₀ - x₁)(y₂ - y₁) (http://mathworld.wolfram.com/Two-PointForm.html)
3. The top-posterior corner of the rectangle, (x₀, y₀), is above the lower edge of the triangle, formed by points (x₁, y₁) and (x₂, y₂) (same equation as before, just flip the comparison)
This is all untested, but it seems like it should work.

Womderful!!! This is pretty much what I was thinking, but I kept overthinking it and confusing myself. I will test this out asap!
Someone's been watching the coding train

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are GMT - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum