Newbie Python Exercise - find distance between points. [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
OK so, in my first programming class. I did all the homework exercises except this one. I cannot quite wrap my head around what is asking me to do (related to the text I read) so I thought I would ask here.
Q: A dartboard of radius 10 and the wall it is hanging on are
represented using the two-dimensional coordinate system, with the
board's center at coordinate (0, 0). Variables x and y store the x-
and y-coordinate of a dart hit. Write an expression using variables x
and y that evaluates to true if the dart hits (is within) the
dartboard, and evaluate the expression for these dart coordinates:
(0,0) (10,10) (6,-6) (-7,8)
I honestly do not know where to start here. Help? Hints?

Your problem isn't Python: it's reading English.
You have a dartboard at (0,0) of radius 10. You're asked to write a program to look at the four points you're given and tell whether or not they would hit the dartboard.
What's the formula for distance from a center (x0, y0)?
r = sqrt((x-x0)^2 + (y-y0)^2)
If you calculate r <= 10, it hits the dartboard.

Related

How to get the flipped coordinates in a rectangle (python) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 days ago.
Improve this question
I am a novice. I don't know how to write the following code:
I have a rectangular box. There is a point in the box. How to get the new coordinates for the point after turning the image horizontally.
How to get the new position of the point after a horizontal flip
Their position has changed from (100, 150) to (100, 50)
Thank you.

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.

What is the right algorithm to detect segmentations of a line chart? [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
To be concrete, given 2D numerical data as is shown as line plots below. There are peaks on a background average movement (with small vibrations). We want to find the values of pairs (x1, x2) if those peaks drops down to average; or (x1) only if the line doesn't back to the average.
There are thousands of such 2D data.
What is the right statistic or machine learning algorithm to find x1 and x2 above without plotting?
Note that this is not an exact answer.
I seriously have no idea what you are trying to do. But I can suggest you a way. Assuming that there is only one peak in the graph and you have all the 2D points data i.e; (X1,Y1)...(Xn,Yn)...
Try calculating the differences between the Y values of adjacent points and get the minimum value if you are doing Yn-1 - Yn (which indicates starting point of the peak). Similarly, get the maximum value which indicates the points with the decreasing peak.

Python: Detecting when an image collides with another image [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 am making this game where you are moving a circle using the arrows keys and there is another circle spawning randomly on the screen. I want to make a piece of code to detect when the first circle collides with the second circle. I know that collidepoint() might come in useful but there is nothing else I really can do. Any help would really be appreciated.
while True:
#if image1 collides with image2
Score -= 1
Pygame supports collision detection between sprites using circles.
The API call you need is:
pygame.sprite.collide_circle()
You can see an example of its use in this question on game dev SE (and don't worry - the bug that question is about has been fixed).
If for some reason you are not using sprites, then circle-circle collision detection is pretty straightforward: just test if the distance between them is less than the sum of their radii.
Or rather, test if the square of the distance between them is less than the square of the sum of their radii (to avoid slow square root calculation):
def circlesCollide(x1, y1, r1, x2, y2, r2):
return (((x2-x1)**2) + ((y2-y1)**2) < ((r1+r2)**2))
Note, that this assumes your circle is not moving fast enough to pass enitrely through the other circle in one update step, in which case you need to do a swept circle collision test.

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