Points, Vectors, Dot Product & Cross Product of 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 7 years ago.
Improve this question
Need help with this of python
Write a program with 3 functions to find out the
(function 1) dot product, (function 2) angle, and
(function 3) cross product of two vectors.
Program should ask a user to input three
points in 3D space such as (x1, y1, z1), (x2,
y2, z2) (x3, y3, z3).
Find two vectors
Find dot product,
Find the angle between two vectors
Find the cross product of two vectors

You will need to import library visual to use the following functions.
Given vector v1 and v2:
To find the angle:
diff_angle(v1,v2)
or
v1.diff_angle(v2)
This gives the angle in radians.
To get the dot product:
dot(v1,v2)
can also be written as:
mag(v1)*mag(v2)*cos(diff_angle(v1,v2))
or
v1.dot(v2))
To find cross product:
cross(v1,v2)
or:
mag(v1)*mag(v2)*sin(diff_angle(v1,v2))
or:
v1.cross(v2)
Given two point p1 and p2, to find vector fromp1top2`:
vector(p2)-vector(p1)

Related

How can you calculate where the middle of the screen is using math in python [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 3 months ago.
Improve this question
I must've skipped school that day because I cannot remember how to calculate the middle of a square.
There are a few different ways to calculate the middle of a square using Python. One way is to find the average of the x and y coordinates of the square's four corners. Another way is to find the point that is equidistant from all four corners of the square.
# method-1
def square_middle(square):
x1, y1, x2, y2 = square
return ((x1 + x2) / 2, (y1 + y2) / 2)
# method-2
def square_middle(square):
x1, y1, x2, y2 = square
cx = (x1 + x2) / 2
cy = (y1 + y2) / 2
return (cx, cy)
frameworks usually report the size of a screen with 2 values or a touple of 2. For example, this is how pyautogui reports it:
print(pyautogui.size())
Size(width=1728, height=1117)
And this is how that framework gets the center for every coordinates tuple:
https://github.com/asweigart/pyscreeze/blob/master/pyscreeze/__init__.py#L579
So you can safely use the example above to get the center of any object on screen, even the screen itself.

How do I calculate this 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 1 year ago.
Improve this question
I have following for loop to extract bounding boxes in an image. Assuming the p is the center point of each box.
The distance formula is: √[(x₂ - x₁)² + (y₂ - y₁)²]. This works for any two points in 2D space with coordinates (x₁, y₁) for the first point and (x₂, y₂) for the second point. You can notice that it is Pythagoras theorem and the distance is the hypotenuse, and the lengths of the sides are the difference between the x and y components of the points.
So once you have p (center point of bounding box) for two boxes you need to just apply the formula. You can also create a loop and do that for all the p variables that you calculate depending on how many boxes you have.

Numpy - how interp function works? [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
I need to understand how numpy.interp function works. This function has a couple of parameters which are vague to me, like: xp, fp, left and right.
I saw an example of this function as below:
X is a numpy ndarray and y is one-dimensional array:
X = np.interp(X, (X.min(), X.max()), (0, 10))
y = np.interp(y, (y.min(), y.max()), (30000, 100000))
Thanks for helping me out!
x are the points which are not in xp but you want their y values i.e. points where you want to perform interpolation
xp and yp are the main inputs based on which 1D interpolation works (these are the discrete data points through which you want to interpolate)
left and right handle the edge case scenarios when x is out of the closed interval range of [xp_minimum, xp_maximum] i.e. the output values to generate incase of extrapolation

Find the top 10 centre most values from each clusters done by k-means using 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 3 years ago.
Improve this question
I have a data frame and I have clustered it into 3 clusters using k-means clustering.
Now I want to find the top 10 centre most values from each clusters.
How to do it using python ?
So, after finding 3 clusters mean you have 3 centroids, which are nothing but 3
datapoints or
vectors of size -> number of inputs right?
so, you also have data points of dataset segregated to their cluster number. For 10 closest points of cluster1, find the distance between points in cluster1 and centroid1.And sort them in decreasing order of distance and extract top 10 points.
Similarly for all 3 clusters.
Example:
centroid1 : (1,2)
points in cluster 1: (2,3) (4,5) (1,1) (2,0) (3,4)
top2 points are : (1,1) (2,3).
based on their distances.

Crop a square shape around a centroid (numpy) [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
I have an numpy array image which contain circles. I extracted the whole x,y centroids (in pixels) of these circles (a numpy array as well). Now, I want to crop a square around each x,y centroid.
Can someone instruct me how to solve it?
Note that I didn't find any question in Stack that deals with crop around a specific coordinate.
Thank you!
If your centroid has indices i,j and you want to crop a square of size 2*w+1 around it on a numpy array a, you can do
a[i-w:i+w+1,j-w:j+w+1]
This is provided your indices are always more than w from the boundary.
If they're not, you can do
imin = max(0,i-w)
imax = min(a.shape[0],i+w+1)
jmin = max(0,j-w)
jmax = min(a.shape[1],j+w+1)
a[imin:imax,jmin:jmax]

Categories

Resources