Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LinearEquation:
- def __init__(self, a, b, c, d, e, f):
- self.__a = a
- self.__b = b
- self.__c = c
- self.__d = d
- self.__e = e
- self.__f = f
- def getA(self):
- return self.__a
- def getB(self):
- return self.__b
- def getC(self):
- return self.__c
- def getD(self):
- return self.__d
- def getE(self):
- return self.__e
- def getF(self):
- return self.__f
- # isSolvable()<=>ab-bc!=0
- def isSolvable(self):
- if ((self.__a * self.__d - self.__b * self.__c) != 0):
- return True
- else:
- return False
- def getX(self):
- return ((self.__e * self.__d - self.__b * self.__f) / (self.__a * self.__d - self.__b * self.__c))
- def getY(self):
- return ((self.__a * self.__f - self.__e * self.__c) / (self.__a * self.__d - self.__b * self.__c))
- def __repr__(self):
- s1 = ("{}x + {} + {}y = {}".format(self.__a, self.__b, self.__e))
- s2 = ("{}x + {} + {}y= {}".format(self.__c, self.__d, self.__f))
- rezultat = s1 + "\n" + s2
- return rezultat
- s1 = LinearEquation(2, 3, 1, 7, 5, 8)
- if s1.isSolvable():
- x = s1.getX()
- y = s1.getY()
- print("Sistemul are solutia ({},{})".format(x, y))
- else:
- print("Sistemul nu are solutie")
- s2 = LinearEquation(2, 3, 2, 3, 4, 1)
- if s2.isSolvable():
- x = s2.getX()
- y = s2.getY()
- print("Sistemul are solutia ({},{})".format(x, y))
- else:
- print("Sistemul nu are solutie")
- import math
- class Punct:
- def __init__(self, xx, yy):
- self.x = xx
- self.y = yy
- def __repr__(self):
- return 'X este {} si Y este {}'.format(self.x, self.y)
- def __eq__(self, other):
- if self.x == other.__xx and self.y == other.__yy:
- return False
- else:
- return True
- def distanta(self, other):
- dis = math.sqrt((self.x - other.__xx) ** 2 + (self.x - other.__yy) ** 2)
- return dis
- class Segment:
- def __init__(self, a, b):
- self.__start = a
- self.__stop = b
- def __repr__(self):
- return 'Segmentul a are: {} iar segmentul b are: {}'.format(self.__start, self.__stop)
- def intersectie (self, other):
- a1 = 1 / (self.__stop.x - self.__start.x)
- b1 = -1 / (self.__stop.y - self.__start.y)
- t1 = self.__start.x / (self.__stop.x - self.__start.x)
- t2 = (-self.__start.y) / (self.__stop.y - self.__start.y)
- e1 = t1+t2
- a2 = 1 / (other.__stop.x - other.__start.x)
- b2 = -1 / (other.__stop.y - other.__start.y)
- t1 = (other.__start.x)/(other.__stop.x - other.__start.x)
- t2 = (-other.__start.y)/(other.__stop.y - other.__start.y)
- e2 = t1+t2
- s=LinearEquation (a1,b1,a2,b2,e1,e2)
- if s.isSolvable():
- x=s.getX()
- y=s.getY()
- p=Punct(x,y)
- return p
- return None
- p1=Punct (2.0,2.0)
- p2=Punct(0,0)
- Segment1=Segment(p1,p2)
- p3=Punct(0,2.0)
- p4=Punct(2.0,0)
- Segment2=Segment(p3,p4)
- p=Segment1.intersectie(Segment2)
- print(p)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement