Finding relative x and y value on a sprite [Gamemaker]

I'm having a little conundrum that may just result from a lack of knowledge of Gamemaker's functionality. I've attached two images to aid explanation.

I have a sprite of a turret (with a gun barrel), attached to a turret object, and at certain points in gameplay this object will spawn another object on top of it (let's call it the 'bullet object').

I would like the bullet object to spawn at the x and y coordinates at the end of the gun barrel. This would be easy to find as a pair of coordinates if the sprite was always stationary, in this configuration. Alas, it is not. It rotates like billy-oh. This means that the x and y coordinates at the end of the gun barrel are constantly different.

How do I find this constantly changing x and y coordinate? I imagine (though am most likely wrong) that there the initial x and y coordinates of the sprite are saved and can be found even if rotated; is there a function that does this? Or do I need to write a script and then call it every time I want to spawn the bullet object?

• stackoverflow.com/a/26311662/1821428 – Dmi7ry Oct 29 '15 at 20:28
• Thanks, this worked very well. I have another related problem, but I'll post another question about that. – Bonfire Dog Oct 30 '15 at 14:06

Thanks, @Dmi7ry, for posting the answer to this question above in the comments. The functions to use here are lengthdir_x and lengthdir_y, as explained in the link to the other question.
For my purposes, I knew that the point on the turret that I want my bullet to appear at was 62 pixels out from the origin. The functions lengthdir_x and lengthdir_yallow you to find a set of coordinates out from an object's x/y origin by specifying how many pixels out from source you want, and in which direction. I knew that I needed to find a point 62 pixels out from origin, and that that point would need to be in whichever direction the turret object (and thus its barrel) was pointing, determined by the image_angle. Therefore:
instance_create(x + lengthdir_x(62, image_angle), y + lengthdir_y(62, image_angle), oBullet)