python – Store coordinates in 2d grid

I am writing a feature for a small pygame program. The idea is that I have a square screen of 500 pixels and I want to place 5 objects per row with the size of width Y height in random order and I need a function to generate and store coordinates.

of random import randint

def gen_coords (width = 50, height = 50, side_of_scr = 500):
"" "Generates random coordinates for objects in rows
that are placed in a 5x5 grid. "" "

coords = []
    for row in rank (5):
# creating a row container
for pos in rank (5):
# range of values ​​in randint reflects that I want the objects
# to be placed with offset from the sides of the screen
x = randint (0.5 * width, side_of_scr - 0.5 * width)

# the distance between the rows is equal to the height of an object
y = 0.5 * height + row * 2 * height
Coords[row].append ((x, y))
return chords

So this

for coord in gen_coords ():
print (coord)


[(177, 25.0), (367, 25.0), (214, 25.0), (284, 25.0), (125, 25.0)]
[(425, 125.0), (446, 125.0), (126, 125.0), (409, 125.0), (187, 125.0)]
[(210, 225.0), (188, 225.0), (215, 225.0), (132, 225.0), (431, 225.0)]
[(303, 325.0), (471, 325.0), (252, 325.0), (26, 325.0), (111, 325.0)]
[(468, 425.0), (127, 425.0), (452, 425.0), (30, 425.0), (345, 425.0)]

I've done this using the list of lists and it's working so far, but I'm looking for the best way to do it. Thanks for the help.

trace – Why are the coordinates of the parametric diagram different from the image?

I am creating parametric equations of objects to find their centroids. With the help of others in a different stack exchange publication, I was able to find a code that can precisely parameterize any closed curve. The only problem is that the coordinates of the pixels in the corresponding image are different from the coordinates for the parametric graph. Here is an example.

enter the description of the image here

enter the description of the image here

The original image is only 320 pixels wide and 37 pixels high, but the frame is more than 500 units wide and the coordinates are also disabled for some reason. Could someone explain why this happens and possibly propose how to fix it? For context here is the code that I have been using.

param[x_, m_, t_] : = Module[{f, n = Length[x]nf}
f = Chop[Fourier[x]][[;; Ceiling[Length[x]/ two]]];
nf = length[f];

2 Abs[f]/ Sqrt[n] Sin[Pi/2-Arg[Pi/2-Arg[Pi/2-Arg[Pi/2-Arg[f] + 2. Pi Range[0, nf - 1] t], .01][[;; Min[m, nf]]]]]tocurve[Line[data_], m_, t_]: = param[#, m, t] & / @ Transposition[data]
img = Import[

img = Binarize[img~ColorConvert~"Grayscale"~ImageResize~500~Blur~3]~ Blur ~ 3;
lines = Cases[Normal@ListContourPlot[Reverse@ImageData[img], Contours -> {0.5}], _Line 1];

ParametricPlot[Evaluate[tocurve[#, 500, t] & /@ lines], {t, 0, 1}, Frame -> True, Axes -> False]

I'm sorry if this is an obvious question. I'm new to Mathematica.

Gaussian null coordinates

I find it difficult to find information about the so-called "Gauss null coordinates", which Wikipedia says is used to describe "near-horizon geometries". Can someone provide a reference where I can read about the basics and how to use them?

How do I get an address from a place with google place if I only have the android studio gps coordinates?

Good I need to get an address of a place with google place if I only have the coordinates android studio gps I have already developed it with the autocompleter and with Geocoder (Geocoder if I get the direction through the cordenas) and it works perfectly but I need to get a description of the most detailed address as well as the api places and my question is if there is any way to do it since I have searched and do not find much information, in advance thank you very much

Riemannian geometry – Cylindrical coordinates in symmetric space ratio

I am interested in the following situation. Suppose $ G / K $ It is a symmetric space of non-compact type and $ alpha $ It is the axis of a hyperbolic isometry. I'm interested in computing the burlap of the function. $ z mapsto d ^ 2 ( alpha, z) $.

Here is an example of this situation.

Leave $ (C, sigma) $ be the quotient $ mathbb {H} / langle z mapsto lambda ^ 2 z rangle $ where $ mathbb {H} $ It is the upper half-plane equipped with its hyperbolic metric. $ dz ^ 2 / | Im z | ^ 2 $. Leave $ gamma $ denotes the geodesic core. If we take the region between $ | z | = 1 $ Y $ | z | = | lambda | ^ 2 $ be a fundamental domain for $ C $ in $ mathbb {H} $, we have orthonormal coordinates $$ { xi_1, xi_2 } = {( without theta) ^ {- 1} partial / partial theta, (r without theta) ^ {- 1} partial / partial r } $$ One can then calculate $$ textrm {Hess} d ^ 2 ( gamma, cdot) = 2d xi_1 otimes d xi_1 + 2d ( gamma, cdot) tanh d ( gamma, cdot) d xi_2 otimes d xi_2 $$ Raising to the universal cover we obtain the desired Hessian.

I'm looking to do something similar. The missing ingredient is a good set of orthonormal coordinates in $ langle alpha rangle backslash G / K $. Is there a source where such coordinates are constructed?

General transfer of coordinates

I am looking for a package or fragment (free) that facilitates the transformation of tensors between space times. What do you suggest?

layout: How to draw different colors in a 2D layout with color depending on the xy coordinates?

I'm doing a composite 2D graphic, combining different types of graphics (Graphics, ListPlot etc.) with Show. A layer of the plots contains a polygon filled with colors that depend on the 2D coordinates in the polygon. (The vertices of the polygon are {{0.6400744901465835, 0.3299704937157755}, {0.29999999497269986, 0.5999999722714001}, {0.15001662467009716, 0.060006658004021524}}.)

To draw the polygon, first I thought about using ColorFunction with DensityPlot, but it seems that it only receives the value of the function itself, not the coordinates. My next attempt was with RegionPlot, which gets the coordinates. This looks like the following code.

(* Functions to calculate the color from the coordinates x and y *)
xyY2XYZ[x_, y_, Y_] = {(xY) / y, Y, - (((- 1 + x + y) Y) / y)};
normalize[x_] : = x / Max @ x
XYZ2sRGB[c_] : = (normalize[( {
      {3.2406255, -1.537208, -0.4986286},
      {-0.9689307, 1.8757561, 0.0415175},
      {0.0557101, -0.2040211, 1.0569959}
     } ).c]) ^ (1 / 2.2)
(* Actual layout *)
RegionPlot[True, {x, 0.14, 0.65}, {y, 0.05, 0.61}, 
 ColorFunction -> 
  Function[{x, y}, 
    If[Max@Abs@Im@# != 0, {1, 1, 1}, Re@#] & @
XYZ2sRGB @ xyY2XYZ[x, y, 1]]], ColorFunctionScaling -> False,
Tracing points -> 250]

Exit of the previous code

But I had to increase PlotPoints to 250Otherwise, the result was too pixelated at the edge, and MaxRecursion It does not seem to affect the output. This results in a long waiting time, and the edge still remains irregular.
In addition, the blue line between the image and the frame is an unwanted artifact.

So, what is a better way to do this?

collision detection: find the coordinates of collided objects in Python

I have a group that contains my aliens and another that contains the bullets that I shot. When I detect their collisions, I want to extract the x-y coordinates of the alien during its elimination in order to place an explosion animation in that location. How do I achieve this? My attempts so far give an error saying that the elements of the group can not be indexed.

This is my first real coding project, so it's still new. I'm using Pygame to make the game.

Current collision detection code:

def check_bullet_alien_collisions (ai_settings, screen, statistics, sb, ship, aliens, bullets, bombs):
"" "Respond to bullet and alien collisions" ""

collisions = pygame.sprite.groupcollide (bullets, aliens, True, True)

#Collect X-Y coordinates here

if collisions:
for foreigners in collisions. values ​​():
stats.score + = ai_settings.alien_points * len (foreigners)
sb.prep_score ()
stats.aliens_hit + = 1
stats.calc_accuracy ()
sb.accuracy ()
check_high_score (stats, sb)  

list – Python coordinates out of range for polygon

I am working on a script whose job is to comb a CSV file full of pixel values. I have used a json file to find the dimensions of a preannoted polygon and I am trying to calculate a value for the average pixels within that object. The pixel_temperature list is a [512][640] Same as the dimensions of the image. I'm using the Skimage polygon functions to calculate all the pixels within the points of my polygon

# Find all the points within the polygon
r = np.array ([y1, y2, y3, y4])
c = np.array ([x1, x2, x3, x4])
x_axis, y_axis = draw.polygon (r, c)

NOTE: x and y in my JSON and mixed, that's why I'm stating the first of and

This produces two nparrays (x_axis, y_axis) of equal lengths (tested with selected random points, they are also coordinates, so they must come in pairs) I am trying to traverse these two lists simultaneously and then calculate my value. This works for most of my polygons but randomly I hit a

Tracking (recent calls latest):
File "", line 232, in 
File "", line 228, in main
parseJSON (jsonFilePath)
File "", line 113, in parseJSON
average_u_value = parseCSVPolygon (csvFilePath, csvFileName[0], x_axis, and_axis)
File "", line 197, in parseCSVPolygon
total + = u_value_calculation (emissivity, pixel_temperature[x[i]][y[i]])
IndexError: List index out of range

Since the lists are of equal length and my pixel_temp list contains all values ​​of 512 by 640, I do not understand why I receive this error.

The error refers to this block inside my parseCSVPolygon function

fileName + = ".csv"
path = csvFilePath + & # 39; / & # 39; + fileName
with open (path) as read_csv:
csvData = csv.reader (read_csv, delimiter = & # 39;, & # 39 ;, quotechar = & # 39; | & # 39;) # Separated by comma (therefore, csv)
for i, data to be enumerated (csvData): # i contains the index and increments each loop while the data contains the value of the cells
length = len (data)
if (length == 0): # In case the length of a row is 0 (empty cells)
index = length - 1 # Extract the last data point in the row
yes (i == 2):
emissivity = float (data[index])
#print (emissivity)
yes (i> = 10):
pixel_temperature.append (data[1:]) # The pixel temperature now has 512 indexes. Each index

#TODO: find out how to calculate the u value of doors (or polygons)
for article in rank (len (y)):
total + = u_value_calculation (emissivity, pixel_temperature[x[item]][y[item]])
average = total / (len (x) * len (y))
return average

I am confused as to the source of this error. Can anybody help me?

Different coordinates in mapbox maps in relation to Google maps?

I have changed a directory site with google maps to mapbox map, due to the google payment policy … Everything is fine, but the same poi coordinates in google maps are in different places in mapbox maps? Why? Is there any formula to solve this problem?