Finding angles in an image?

I’m working on a Scorched Earth / Worms type game. The map is randomly generated “uneven” terrain. Checking for collision is easy enough with .getRGB(), however I want some projectiles to bounce around before exploding. How should I go about finding the angle of the surface that the projectile hit in a map like this?

http://p.twimg.com/Ab2HVZqCEAMuW2F.png

The blue background is a separate image from the ground graphic, and is not used for collision detection. Also, when a projectile explodes, I will be erasing a circle out of the ground image. I thought about using an array of lines to define the outline of the surface, but trying to figure out how to cut out a segment and adding lines for the hole that was created, sounds like a pain. The easiest way seems to be scanning pixels around the projectile (after it collides with the ground) to try to figure out the angle, but then how far out should I check, and how would I figure what is too far out? Has anyone here done something like this before?

For bounce you can implement physics library or do something harder. In my approach, I will identity each image based on the horizon so I can fugure out the angle given by colliding it. Use some standar small images for terrain like

|

|

/#

/

It’s not so hard, actually. The easiest way to do it is just to count adjacent pixels and have pixels on the right do +1 to the slope and on the left -1, more or less. Depending on how many pixels you sample (3x3 or 4x4 usually) you can get more defined slopes.

Here is some code I have that I used to find angles in a game I made a while ago.


Vector hitVector = new Vector(0,0);
for(int i = 0; i < surrounding.length; i++)
{
	Point point = surrounding[i];

	if(image.getRaster().getPixel((int) c.x + point.x, (int) c.y + point.y,size)[3] == 0) continue;

	if(point.x < 0) hitVector.x += -1.0f / (-2.0f + point.x);
	if(point.x > 0) hitVector.x += -1.0f / (2.0f + point.x);
	if(point.y < 0) hitVector.y += -1.0f / (-2.0f + point.y);
	if(point.y > 0) hitVector.y += -1.0f / (2.0f + point.y);
}