How to create 10,000 random coordinates in python? [closed] - python

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Hello I've been set a project where I have to generate 10,000 random coordinates (x,y), using the random module in python and then output them all. The coordinates HAVE to be decimal numbers between 0 and 2. I've had a look around on the internet but I can't seem to find anything that is helping me. Can anyone on here help me? Thank you.

Or use numpy:
import numpy as np
coords = np.random.rand(10000, 2) * 2

Use the random module within a list comprehension to generate a list of random coordinate tuples:
import random
coords = [(random.random()*2.0, random.random()*2.0) for _ in range(10000)]
This will give you 10,000 tuples (x, y), where x and y are random floating point numbers greater than or equal to 0 and less than 2.

Related

Python, Angle between 2 points [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
My vehicle is driving along it’s locale Y-axis. When it encounters a hill the front lifts up and creates an angle with the rear. How can I ask python to return the angle for the vehicle to rotate on its X-axis ?
I found this but it doesn't work :
mathutils.geometry.box_fit_2d(points)
Returns an angle that best fits the points to an axis aligned rectangle
Parameters
points (list) – list of 2d points.
Returns
angle
Return type
float
to get the angle of the line you can pretty easily do it with a simple math
y1=kx1+l
y2=kx2+l
y1=kx1+y2-kx2
k=(y1-y2)/(x1-x2)
and this k is your tangent. so you just use numpy arctan
import numpy as np
angle=np.arctan((y1-y2)/(x1-x2))[0]

Python: How to check whether a Circle has equal radius along all 360 degrees [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Using Python, I want to check whether a circle has an equal radius along all 360 degrees. Actually, I have segmented a circular shape from an image and then want to check whether it has a same-sized and equal radius along all the 360 degrees or not.
Can someone kindly help and tell how to do that?
In Python, OpenCV is a strong choice for an imaging library. You'd want to fit a contour to the circle and use moments to check the properties. You can fit an ellipse and see how close the major and minor axis of the ellipse match.
See this tutorial/docs for details.
Also, this question should help.

trouble in finding pixel by pixel difference of two images [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
rows, cols = img1.shape[:2]
x = np.random.randint(0, 255, (w1, h1))
for i in range(rows):
for j in range(cols):
k = x[i, j]
I am finding difficulty in completing the code for finding the pixel by pixel difference of two images in Python OpenCV. Could you please help me with the right code.
In any case you should avoid loops over single pixels, but use operations which work on full images
You may want to have a look at the general OpenCV Python tutorial.
There is a chapter on arithmetic operation on images, this is what you are looking for:
http://docs.opencv.org/3.1.0/d0/d86/tutorial_py_image_arithmetics.html#gsc.tab=0
The pdf version of the complete tutorial can be found here:
https://media.readthedocs.org/pdf/opencv-python-tutroals/latest/opencv-python-tutroals.pdf

Randomly generated dungeon with Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm trying to figure out how to create a completely random maze/dungeon for a small text game I'm working on. I'm really not sure where to start since I've never done anything like this before. How do I do this? I need the rooms to know what mobs it holds, what items are on the ground, where the exits are and what other rooms they go to. Any help is appreciated.
You can make an 2 dimentional int array (your map). Each "object" such as an item or exit gets another number.
for example:
0 = no object
1 = knife
2 = sword
3 = helm
When you need to make it posible to combine objects on one field (for example put an sword and an helm on one field) you can create an 3d array. So you can add an object on top of another object.
You can generate and random x and y whitin your array dimentions and give this an random number within your object scope (in this example between -1 and 4)
Hope this helps ;-)
Since this is a very broad question I will just give you a general answer. You are probably going to want to make a new class that will contain the data for a room. In this class you could have variable that could store randomly generated numbers (using the random module) and then have methods use those numbers to determine the layout, monsters, and items in each room. All you would then have to do is to have a 2D or 3D grid (probably using lists of the room class) and randomly fill the grid with rooms that each contain random data.

How to offset random sine angles as a whole? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have randomly generated sin values using angles:
sin(12)
sin(33)
sin(75)
sin(125)
...
I want to add a fixed rotation to all of these and wondering if there is an elegant way to do this? I was thinking of doing some comparisons and checks to see if the angle + my_additional_angle is negative and greater than certain values so as to add my fixed angle appropriately but wanted to ask for a simpler way first.
Also this has to be solved within these constraints, i.e. I can't use matrices, etc, because the application that defines these is very limited.
Lastly the random angle is between 0 and 180. The angle I am adding can be anything.
First off, trig functions work in radians, not degrees, so you almost certainly want:
sin(radians(12))
sin(radians(33))
# etc
To add an angle, if you do so before you take the sin it's really easy, just
sin(radians(12+angle))
sin(radians(33+angle))
It should not matter if the angle if negative or greater than 360, sin will still work correctly, so that sin(radians(12)) == sin(radians(12+360)) == sin(radians(12-360)).

Categories