## Trigonometry/Geometry Library - Collision, Perimeter, Etc...

User projects written in or related to FreeBASIC.
Pritchard
Posts: 5492
Joined: Sep 12, 2005 20:06
Location: Ohio, USA

### Trigonometry/Geometry Library - Collision, Perimeter, Etc...

Thanks to Relsoft, Dr. D, and me putting myself in Geometry, I am able to release this library. Relsoft and Dr. D deserve all credit for teaching me collision detection :P

This library's uses pretty darn fast methods. The 2D physics AND Collision.bas goes around 7000 frames per second here.

Note: Was compiled under Windows XP. If you have trouble with it and it's not a lower than .16 issue, try compiling it yourself.

The Lib Supports the Following:

• Tested on Version .16 Unstable, so no guarantees for you .15'ers
• 1D, 2D, and 3D Trigonometric Functions with Single Digit Precision
• Spherical Against Line Segment Collision Detection for All Dimensions Supported:

Code: Select all

`Collision_Detection_Dimension(Boundary Type, Boundary Start, Boundary End, Object Position, Radius)`
Boundary Type is the value of which normal to use.
• Spherical Against Spherical Collision
• A ton of other stuff, really (function list below) :P

Type List:

• Geo_Vector
• Geo_Segment
• Geo_Collision_Type
• Enum: Geo_Option

Function List:

• Segment_Collision
• Object_Collision
• Triangle_Collision
• Closest_Point_On_Line
• Get_Angle
• Get_Cos_Angle
• Get_Distance
• Get_Dot_Product
• Get_Endpoint
• Get_Magnitude
• Get_MidPoint
• Get_Triangle_Perimeter
• Normalize_Vector
• Vector_Normal 'Normal between two vectors

So what are you waiting for? Test and complain to me about it people:

Last edited by Pritchard on Jul 26, 2006 17:57, edited 17 times in total.
voodooattack
Posts: 605
Joined: Feb 18, 2006 13:30
Location: Alexandria / Egypt
Contact:
works amazingly well here! :)

and i'm using .15, just a "fbc Geo_Math_Lib.bas -lib" and it's done ;D

i wish i could use that within Nano :P (evil laugh!! MUAHAHAHAHA!!) >:P

i must say i'm impressed.. especially with that GetAngle proc ;)
Deleter
Posts: 975
Joined: Jun 22, 2005 22:33
voodooattack wrote:works amazingly well here! :)

and i'm using .15, just a "fbc Geo_Math_Lib.bas -lib" and it's done ;D

i wish i could use that within Nano :P (evil laugh!! MUAHAHAHAHA!!) >:P

i must say i'm impressed.. especially with that GetAngle proc ;)

Well if you add an extension to every function I think you could use it in nano. :P
voodooattack
Posts: 605
Joined: Feb 18, 2006 13:30
Location: Alexandria / Egypt
Contact:
Deleter wrote:Well if you add an extension to every function I think you could use it in nano. :P

*goes to prepare his artillery* >:D
relsoft
Posts: 1767
Joined: May 27, 2005 10:34
Location: Philippines
Contact:
Now finish that party game. :*)
Pritchard
Posts: 5492
Joined: Sep 12, 2005 20:06
Location: Ohio, USA
relsoft wrote:Now finish that party game. :*)
Shhh!!!! :P
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Pritchard
Posts: 5492
Joined: Sep 12, 2005 20:06
Location: Ohio, USA
1000101 wrote:By the way, it's Magnitude.

http://dictionary.reference.com/search?q=magnitude

EDIT: Fixed. Thanks for reading the first post, and complaining to me.

Double Edit: Added 3-D examples, not finished. I have to learn 3D first...
Zamaster
Posts: 1024
Joined: Jun 20, 2005 21:40
Contact:
how bout we use it in ATTO.... atto anyone? atto please? I WANT ATTO!!!!
Pritchard
Posts: 5492
Joined: Sep 12, 2005 20:06
Location: Ohio, USA
Update:

Finally! I have just added Object to Object (Circle to Circle) collision. Updated link in first post.

Changed:

Collision_Detection_2D is now Called: Segment_Collision

Object to Object Collision is called: Object_Collision_2D (only 2D is available)

New Option Added for Object_Collision - First parameter is an Enum. Either Geo_Physics or Geo_No_Physics. Geo_No_Physics won't return the normals, so it's slightly faster.
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Zamaster wrote:how bout we use it in ATTO.... atto anyone? atto please? I WANT ATTO!!!!

I had already planned to use line-collision detection in atto. The ships will have a line-loop describing the outside edges and if weapons fire crosses one of said lines, then a hit will be scored.
Pritchard
Posts: 5492
Joined: Sep 12, 2005 20:06
Location: Ohio, USA
1000101 wrote:I had already planned to use line-collision detection in atto. The ships will have a line-loop describing the outside edges and if weapons fire crosses one of said lines, then a hit will be scored.
Hahah. Add this line to the Object_Collision_2D, then compile and run Object_Collision.bas in the Two Dimensional examples folder:

Code: Select all

`Line (c.x, c.y)-(d.x, d.y)`
You get a line outside of the red ball reflecting the white one :P
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
It's an interesting bit of a math lib, I'll have to take a look at it a bit more. However, we're not that far yet. We're still working on code even before that happens. Once we have something too collide, then we'll worry about checking for that :D
elcalen
Posts: 116
Joined: Oct 09, 2005 23:52
Location: Finland
Contact:
Type Geo_Segment_1D is dublicated in the .bi file. Gave me an error when I tried to compile it...

Also you have this line in the examples: #include "Fbgfx.bi". You should use "fbgfx.bi" for it to compile in Linux. Linux is case sensitive!

I've only tried one or two examples, but looks good so far. Thanks, mate.
Pritchard
Posts: 5492
Joined: Sep 12, 2005 20:06
Location: Ohio, USA
elcalen wrote:Type Geo_Segment_1D is dublicated in the .bi file. Gave me an error when I tried to compile it...

Also you have this line in the examples: #include "Fbgfx.bi". You should use "fbgfx.bi" for it to compile in Linux. Linux is case sensitive!

I've only tried one or two examples, but looks good so far. Thanks, mate.
Thanks for the complements and complaints! Geo_Segment_1D is duplicated because I added it at the last minute. I only had it for one dimension because I never used it, so I forgot all about it.

Case sensitivity is important. I'll have to remember that! Be right back in a minute with the update!

EDIT: Fixed, updated in first post.