# 3D Looking for spherical terrain collision alogrithms

## Recommended Posts

I googled for terrain collisions but found only some sources about flat worlds.   I want collision detection for spherical terrain worlds.   I have "3D Engine Design for Virtual Globe" book but it did not mention any algorithms about collision detection for landing, rolling, walking, crashing, etc...   Does anyone have any good sources for spherical terrain collision detection?

##### Share on other sites

Do you use cartesian coordinates and have a spherical object as ground? Or do you use spherical coordinates over a "flat" world?

##### Share on other sites

Do you use cartesian coordinates and have a spherical object as ground? Or do you use spherical coordinates over a "flat" world?

I mean spherical terrain object as ground in cartesian (XYZ) coordination for collision detection.

2 Circle checks.

##### Share on other sites

Well in that case basically any collision detection would work. Testing intersection against a sphere is as easy as comparing distance vs radius, when the distance is smaller, there must be a collision.

But you probably don't have only spheres in your game. And your sphere is probably a spherical model made up out of triangles. And the problem with collisions really isn't detection but resolution.

And if you don't know that, you will have a hard time writing that by yourself.

I'd say use a physics library to detect and resolve collisions. Don't know what language or engine you are working with, but you can find one (free ones even) for almost any language or engine.

For anything but really simple cases writing it yourself is ... insane. And unnecessary.

##### Share on other sites

A few random thoughts:

Taking into account the last threads on this i think we don't have spheres here and in case of the earth a general sphere intersection test can be off by 20km. In extreme cases it could result in mid air collision with terrain 20km above the poles or a subterranean flight below the moho under the equator. Space gamers call the latter "lithobreaking" in extension of "aerobraking" in the upper atmospheres of planets or gas giants 🙂

If these details matter we need ellipsoid intersection tests for the big overall scale (simple i dare say).

The atmosphere should be taken into account for small body against big body. That can be arbitrarily complex i assume, so further specification is needed. You mentioned spaceflight in another thread. What collides with what ? Spaceships ? Asteroids ? What about atmospheres ? Drag and friction ? Terrain detail ? Orbital speeds ?

A small slow moving body in atmospheric flight (a plane, or anything having slowed down to terminal speed in an atmosphere) must be tested against local terrain i'd think. That would probably result in an intersection test of a bounding shape of the flying contraption against the terrain mesh in the direction of flight.

More ?

##### Share on other sites

I found a book called “Collision Detection” on Amazon and it explains about many different kinds of simple collision detection like AABB, OBB, sphere, etc. in chapter 4.  I will study it more.  Also other books called “Physics Engine” and “Game Engine Architecture”.

I have books called “Atmospheric and Space Flight Dynamics” and “Orbital Mechanics”  about aerobraking, re-entry, etc..

Yes, I mean space plane, space shuttle, and capsule for landing, launching and docking with ISS.

I now implemented reference frame, orbit and rotation model on planets and stars for orbiting and rotating locally.  I got VSOP 87 and JPL Ephemeris data for planets and P03 precession model for earth rotation.  I implemented follow function in player class to follow any object locally by using reference frame for orbiting, etc..

For more tests, I moved earth position to 149.6 million km away from origin. No jitters a few meters above ground! Yay!

##### Share on other sites

Hi if you want code (my game engine made during PhD):

isCollide method in either bounding object.

##### Share on other sites

Just find an intersection with flat ground, any algorithm (distance functions,  maxmip pyramid, csm) is valid,  but transform (rotate) the bound box before finding ray-box intersection (vertex shader), then transform your ray into local bbox coordinates and voila, you get it!

This is an example of my 3 years old raycasting work made during my PhD))

As you can see the method is robust butit need to be heavy optimized to use in real time engines

## Create an account

Register a new account

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 9
• 15
• 9
• 11