Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Example : Traingle Circle Collision :)
 New Topic  Reply to Topic
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 17 2004 :  7:22:39 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
Hi

I've seen an example for this in Almar's home page

and I have learned another method for the test from SuperC Here :
http://www.vbgamer.com/msgboard/topic.asp?TOPIC_ID=143

soo here is my test

Download Attachment: TriangleCollision.zip
2.86 KB

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jun 18 2004 :  12:02:44 AM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
It doesn't always work. Here is a picture of what I'm talking about.

Download Attachment: failedtest.jpg
21.02 KB

Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 18 2004 :  10:37:38 AM  Show Profile  Visit game_maker's Homepage  Reply with Quote
Yes,True and this is also happening to the code in Almar's home page

that's why I added Accuracy

if you put Accuracy = 256 for example you will have 99.99% (we can say 100%) it will test 256 point (in triangle)
Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 18 2004 :  5:51:19 PM  Show Profile  Reply with Quote
But it will be much slower...
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 18 2004 :  6:52:32 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
Also True, because we know speed = k / accuracy

You can not (or let say) it's very hard to bind or find a relation between a curve (circle) and poly (triangle) and that's what both test's do

Will if we can find the center of our triangle and make a radius and so a circle then check circler collision if true then check our test

I didn't bring a new Idea for collision the Idea is totally same the procedures is sort of different
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Jun 19 2004 :  08:28:50 AM  Show Profile  Reply with Quote
Do you know how to find the center point of a triangle?

Whatever. Who knows...
Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 19 2004 :  1:29:41 PM  Show Profile  Reply with Quote
There is a way to do it geometrically... It involves bisecting all the sides of the triagle and drawing perpendicular lines through the points. Assuming all goes well, that will give a point that can create a perfect circumscribed circle, the circumscribed midpoint (BTW, If you do a similar thing with the angles, you will get the INSCRIBED midpoint) I'm sure there is a way to do it algebraically, also... Try google

Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Jun 19 2004 :  3:23:34 PM  Show Profile  Reply with Quote
Yeah, I remembered that but I didn't remember exactly if it were the sides of the triangle or the angles or whatever That is what happens if you last about 2 years without seeing a similar thing in school...

Whatever. Who knows...
Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 19 2004 :  3:52:56 PM  Show Profile  Reply with Quote
You could just calculate 2 of the side midpoints (very easy since you know the endpoints) and the slope of each of those segments, then you can find the perpendicular lines and their intersection. It may be a little computationally expensive, but as long as you aren't doing it for 100,000 triangles per frame you should be okay...
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Jun 19 2004 :  4:00:02 PM  Show Profile  Reply with Quote
Probably it will be needed only once, as long as the triangle shape doesn't change. I will try to do that with this example.

Whatever. Who knows...
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Jun 19 2004 :  4:17:28 PM  Show Profile  Reply with Quote
See, I just corrected the problem this code had just by adding a point-in-circle test for each vertex
Also added an FPS counter. Get it here...
EDIT: Also, using this pre-check, an accuracy of 16 should be more than enough. 8 is already good (acceptable) for not very precise checking. (I have tested both)

Download Attachment: TriangleCollision.zip
3.47 KB

Gotta work on the center-point calculation now...

Whatever. Who knows...

Edited by - VBBR on Jun 19 2004 4:30:26 PM
Go to Top of Page

Serpwidgets
Neophyte

1 Posts

Posted - Jun 19 2004 :  5:34:55 PM  Show Profile  Reply with Quote
Hmm... when checking a collision between a line segment and a circle, there are two possible cases where there is an intersection:

1- An endpoint of the segment is within the circle.

2- the line segment collides with a radius of the circle which is perpendicular to the segment.

If neither of these cases are true, there is no collision.

Out of curiosity, are you talking 2-d or 3-d objects (circles or spheres?) and are you working in 2-d or 3-d space?

Here's my method of determining 2-d line segment collisions within 2-d space. I didn't thoroughly check what was in the attachments, but I saw sin and cos and other really slow functions being used, so I thought this might help. :)

----
  
''''Returns only true or false, doesn't care about location
'this function at most performs the following number of operations:
'Multiply = 6
'Divide   = 2
'add/sub  = 15
'Local Subobject lookups = 24
'Global subobject lookups = 0
Public Function CollideSegments(p1 As Vert2d, p2 As Vert2d, p3 As Vert2d, p4 As Vert2d) As Boolean
Dim t As Single, s As Single 'determinants of the 2d matrices  
Dim theta As Single 'bottom of s&t equations  
  
    theta = ((p2.X - p1.X) * (p3.Y - p4.Y)) - ((p2.Y - p1.Y) * (p3.X - p4.X))  
    s = (((p2.X - p1.X) * (p3.Y - p1.Y)) - ((p2.Y - p1.Y) * (p3.X - p1.X))) / theta  
    's is the porportion, from point 3 of line 2, of the length of line2 at which the collision occurs  
    If s < 1 Then 'if the number is >1 or <0 then it's not within the length of the line...  
    If s > 0 Then
        t = (((p3.X - p1.X) * (p3.Y - p4.Y)) - ((p3.Y - p1.Y) * (p3.X - p4.X))) / theta  
        't is the porportion, from point 1 of line 1, of the length of line 1 at which the collision occurs  
        If t < 1 Then
        If t > 0 Then
            CollideSegments = True
        End If '0 < t < 1  
        End If
    End If '0 < s < 1  
    End If
End Function
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 19 2004 :  5:36:17 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
Nice

this would increase some accuracy at corners

hmmmm, I have add a Circle to Circle Collision to fast our collision

OK now we have :


  • Point in Triangle Test

  • Point in Circle Test

  • Circle-Circle Test



We need all of them to perform a nice Trinagle-Circle test

Download Attachment: Triangle Collision.zip
3.33 KB
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 19 2004 :  5:40:05 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
you can avoid sin & cos functions if you identify your accuracy (you know what I mean ? )

BTW : is there an use for this test (I never programmed 2D Game)

Edited by - game_maker on Jun 19 2004 5:50:50 PM
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Jun 19 2004 :  6:29:27 PM  Show Profile  Reply with Quote
I have just made a small modification, put an "Abs" before the subtract operations in the distance calculations. We must work with absolute values because if you put negative numbers it will go crazy

Download Attachment: Triangle Collision.zip
3.55 KB

Whatever. Who knows...
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 19 2004 :  6:47:19 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
VBBR :

My friend we don't need abs() ,,

  
(a - b) * (a - b)  
  


Is Always positive

assume c = (a - b) then

  
(a - b) * (a - b)  
  


=

  
c * c  
  


=

  
c ^ 2  
  


that's why it's always positive

Edited by - game_maker on Jun 19 2004 7:39:23 PM
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.39 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.