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]
Related
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 9 days ago.
Improve this question
I want to calculate the normal vectors to the chessboard as shown in blue in Python.
chessboard
Ideally each vector should be about 2x the width of the square it is in.
So far I've labelled the four corners of my chessboard, and used cv2.findHomography to get the homography matrix which translates the normal image into a flat image.
normal flat
I was hoping that I could multiply the normal vector in flat space, (0, 0, 1), through the inverse homography matrix to get the normal vectors in the original space, but this hasn't worked at all.
The paper I am following suggests this
part1
part2
but I cannot see how to get these values from the 4 corners of the chessboard. Is there something in cv2 that can help?
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.
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.
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.
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)).