Making a shell/bullet Spawn at the tip of the cannon

I am having a very hard difficulty finding out how to do this.
Here is a scenario

When a tank cannon shoots, what I want is make the shell come out on the tip of its cannon. The same thing when the cannon is facing on a different angle.

I only know the rotation thing but not these trigonometric function I am looking for.

It would be the Sin and Cos of the Angle * the magnitude of the radius for each Axis.
Make sure the Angle is passed to the functions in Radians
It would be along the lines of:

You may need to experiment with the above to match your idea of where 0 degrees is (is it pointing straight up, like a map or compass, or straight to the right, like in mathematic text and graphs), and the direction of rotation (the compass angle rotate clockwise, while math graphs, typically rotate counter clockwise).

The Sin and Cos functions return the same "Sine" wave over a range of values, but the Cosine "wave" leads the Sine wave by 90 degrees (90 degree phase shift).
If you plot Sine and Cosine values, one on the X and the other on the Y, over a range of 360 degrees you get a circle. Since the function returns values between -1 and 1 you can simply multiply by a radius value to make the circle as big as you want.

The Cos of 0 degrees is 1.
The Sin of 0 degrees is 0.

The Cos of 90 degrees is 0
The Sin of 90 degrees is 1

The Cos of 180 degrees is -1
The Sin of 180 degrees is 0

The Cos of 270 degrees is 0
The Sin of 270 degrees is -1

So, if you us the Default windows orientation , where the Y axis increases as you move down the screen, then, the example code above would have 0 degrees pointing down and as the angle changed the rotation of the line would be counter clockwise.
So, if you want 0 degrees to be up and rotate clockwise, simply negate the Y value.
RX = Math.Sin(Angle) * Radius
RY = (-Math.Cos(Angle)) * Radius

If you want 0 degrees to be off to the Right, then switch Sin and Cos.
RX = Math.Cos(Angle) * Radius
RY = Math.Sin(Angle) * Radius
This will rotate clockwise, so it you want counterclockwise, negate the Y again.

__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

what I made is add the results of RX and RY to the origin of the cannon and it did show on the position I wanted but what I observed it works only ( or im just mistaken ) on cannon that are barrels is placed on the middle just like the modern tanks today. I having a problem on a SpaceCrafts cannon which is placed on the side because sometimes it works sometimes its not, some angles work ( I mean the shell comes out on the barrels tip ) and some angles dont ( It spawn on a wrong angle were the cannon is not facing at) or just some of my calculation is wrong

i did what exactly you solve.
and this is how apply the calculations

RX and RY are "Relative" to some center of rotation.
So, if .cannon.origin refers to the center of rotation for the cannon, then it should work regardless of where the cannon is located. If .cannon.origin refers to something else, i.e. the upper left corner of where a bitmap of the cannon image should be drawn, then it will be off, and you will have to add some offset to the origin to get to the center of rotation.
You could for testing simply loop over the range of 360 degrees and plot the circle that should represent the end of your cannon travel and see if it agrees with what you see when you rotate the cannon through its range.

I can't say much else, since I don't know how you are doing your rotations, and what your coordinate system is for a given situation. Since GDI+ supports drawing transformations through the use of the graphics matrix there are so many possible ways you could be handling your rotations, I wouldn't hazard a guess.

__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET. subscribe