Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python vector class

just make a class for vectors:

from math import sqrt, cos, sin

class Vector:
    def __init__(self, start_x, start_y, end_x, end_y):
        self.vector = [start_x, start_y, end_x, end_y]
        
    def get_mag(self):
        return sqrt((self.vector[0] - self.vector[2])**2 + (self.vector[1] - self.vector[3])**2)
        
    def rotate(self, angle):
        new_vector = [self.vector[0],
                      self.vector[1],
                      self.vector.get_mag() * cos(angle) + self.vector[0],
                      self.vector.get_mag() * sin(angle) + self.vector[1]]
        self.vector = new_vector
        return self.vector
    ............................many more functions
   
  
  vector = Vector(x1, y1, x2, y2) #Creating a vector
Comment

PREVIOUS NEXT
Code Example
Python :: python requests insecure request warning 
Python :: best way to access nested key in python 
Python :: percent sign in python 
Python :: python get pattern from string 
Python :: pytest create server 
Python :: python selenium console log 
Python :: sorted python 
Python :: seaborn countplot hue stacked 
Python :: insert function in list 
Python :: shift in python 
Python :: create QAction with icon in pyqt 
Python :: how to import functions from another python file 
Python :: mongodb and python 
Python :: sorted string 
Python :: infinite while loop in python 
Python :: django add queury parameters to reverse 
Python :: How to Replace substrings in python 
Python :: remove str to set in python 
Python :: python class without init 
Python :: Reverse an string Using Loop in Python 
Python :: A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N. 
Python :: putting in text in python 
Python :: python hash 
Python :: binary search tree in python 
Python :: desktop notifier in python 
Python :: how to find duplicate strings in a list of string python function 
Python :: Convert a Pandas Column of Timestamps to Datetimes 
Python :: assign exec function to variable python 
Python :: from a list of lists - find all length of list 
Python :: Python NumPy insert Function Example Working with arrays 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =