Finding coordinates of the circumference of circle in pygame - pygame

in pyGame, I drew 2 circles. 1 that is stationary and one that moves with the arrow keys. So, I want the moving circle to bounce back once it touches the stationary circle( I want it to bounce off the stationary circle not the window.)
To do that I need to find the coordinates of the circumference of the stationary circle. But I do not know the specific module. Can someone suggest a module or an alternate solution.

What you actually need is to find each circles center and radius, then check the distance between the centers, if the distance is less than or equal to the two radii then you know you have a collision. I'll give an example to help:
Say you have circle A, fixed at the point (0,0) with a radius of 5px.
Circle B is at (0,10) with a radius of 3px, which is moving towards the point (0,0).
So, at first we know the distance between the two centers ((0,0) and (0,10)) is 10px, and since 10 is less than 5+3 we know the two circles are not touching.
Now at some point circle B will get to the point (0,8), at this moment when we check the distance between the circles we will get 8, which is equal to 5+3, so we have a collision.
I don't know which libraries and functions you will need to do this, but hopefully this has helped you find the right thing to search for. Basically you need to get the centers, the radii and the distance between two points (the two centers).

Related

libGDX - Delete/Subtract regions of a texture from SpriteBatch?

I have a number of square regions in my game screen which, when actors move across these regions, I want the background image to show through from behind.
So, is it possible to draw to a SpriteBatch such that a region is subtracted/deleted from the texture (effectively "punching a hole" in it)?
I can't think how else to achieve this... Scissors seem incredibly impractical for my purpose, as I want to clip the areas INSIDE a number of squares. This is the inverse of Scissors - which clip areas OUTSIDE the scissors' bounds. The thought of calculating dozens of Scissor regions to fill the inverse areas between an assortment of square regions seems too impractical to be the solution... especially if the regions are moving.
Any help or suggestions appreciated!
UPDATE: Image attached.
I want the background to always be visible in the areas marked with the dotted lines. The dotted areas will move, so I'd rather not create more sprites from the background to lay on top, but rather have parts of the actors intersecting the dotted squares not be drawn. (Or any method that will achieve the same effect.)
I think the best hack is to not try and be so precise about clipping your actors, but to just re-draw the background on top the actors (and to clip that).
Specifically:
draw the whole background
draw your actors/sprites
draw the background with one cliprect for one part that "shows through"
draw the background with another cliprect for the other part that "shows through"
draw the dotted boxes around your cliprect areas
Great image, by the way. Easily worth 1000 words. :)

AS3: 3D axes rotation

I've built a 3D icosahedron in AS3 that I'm going to use as a 20-sided die. With rotationX, rotationY, and rotationZ all set to 0, it looks like the top left picture. Now I'm trying to find the proper rotations for each number so that the face is perpendicular to the screen, like in the top right picture for #1. The problem is that when I rotate it one way, the axes of rotation are changed as well. For example, in the bottom left picture when I was trying to do #2, I set rotationZ to 108, but now rotationX will not turn it straight downwards as it did before.
I could just eyeball it and get approximate rotations that looked about right, but I would rather have exact rotations. Any ideas?
Nevermind, I needed to use Matrix3D instead for my rotations.

AS3 spin text around center?

I am trying to get an effect like this:
http://www.welcomeanimations.com/welcome_animated_gifs_rotating_sign_orange_chrome_k_1.htm
I have tried all sorts of things:
Matrix translation/rotation - spins the text around the 'Z' axis, instead of 'Y'
Adding TextField to a sprite, and Sprite.rotationY++: reg. point is upper left corner
Adding to MovieClip - same as above (an article said MovieClip's reg. point was centered).
This should be trivial?!?! Help me stackoverflow, you're my only hope!
So you have to remember, Display objects scale and rotate around their local coordinate system. so when you put a textfield in a sprite, you need to center it in that sprite's coordinate system. And doing that for textfields is annoying because their width/height isn't always accurate but there is trick for that: get visual bounds, but normally you can take half of somethings width and height
I've created a prototype for you on wonderfl so you can see the solution working in action. Click on the blue square to see how the local coordinate system messes with the rotation
Finally as you use thing you might find things not rotating in 3D space quite right, this should be able to fix that.

Get a square region of earth

I have a certain region given by the coordinates of the lefttop corner and bottom right corner. However, the region formed is not square since the radius of the circle decreases as the latitude increases. In my case, there is a difference of 3-4 km when I calculate the distance using top two coordinates and the bottom two coordinates So, how can I get a square region. I can't suppose that the the region bounded by the lefttop corner coordinate and bottomright coordinate is square. I want a region where the top two corners have a distance of x miles and the bottom two corners have a distance of x miles. Suggestions?
If you aren't into super-accuracy (ie the words WGS84 and oblate spheroid mean nothing to you) then it's simply a matter of calculating the km/degree of longitude at the upper latitude and then shifting the longitude of the two corners out a little, one east and one west.
Roughly:
Latitude: 1 deg = 110.54 km
Longitude: 1 deg = 111.320*cos(latitude) km
http://en.wikipedia.org/wiki/Latitude
Being precise, you cannot have square region on sphere surface. If you correct the distance of top 2 coordinates, then the "right" angles will not be 90 degrees and who knows if the vertical sides would be straight lines!
Google maps projection naturally gives you square in [lat, lon] 2D space, which is correct for most purposes - I also use this geographical "rectangle" grid of 11x11km squares on small spatial scales (400x200km) with no problems. If you neglect the small difference, your life will be much much easier. If you don't, I really cannot assure you the problem of exact rectangle on sphere surface even has any solution!

Align the coordinate labels of the triangles, so that they never collide with each other. Actionscript 3

Im trying to achieve something similar to the flash movie in the below link.
http://mathopenref.com/coordtrianglearea.html
As we drag the points of the triangle, the coordinates labels, ( A(1,2)) are properly aligned and arrange themselves so that they never collide with each other and never falls inside the triangle.
Please guide me..
Thanks in advance.
in the example you gave, the textfield seems to be aligned outside the triangle on the angle bisection of the corresponding corner.
for the position in one corner, take the two vectors to the other corners. normalize them and then add them and normalize the resulting vector again. this gives you the vector v of the angle bisection in that corner. multiply the vector with a negative constant and add it to the corner, and you'll obtain a position p outside the triangle. finally, if the angle of v is between pi/2 and -pi/2 (pointing right) align the right border of the label to p, and the left border otherwise.
for simple vector calculations, please see flash.geom.Point.