def __init__(self, point1, point2=None, **kwargs): self._vertical = False self.places = 7 p1x = float(point1[XCOORD]) p1y = float(point1[YCOORD]) if point2 is not None: # case A # normalize point order to assure consist signs for slopes # +slope goes up and -slope goes down self._slope = 0 self._angle = 0 p2x = float(point2[XCOORD]) p2y = float(point2[YCOORD]) if p1x > p2x: p1x, p2x = p2x, p1x p1y, p2y = p2y, p1y dx = p2x - p1x dy = p2y - p1y if dx == 0.: # line is vertical self._x = p1x self._set_angle(HALF_PI) else: self._set_slope(dy / dx) elif 'slope' in kwargs: # case B self._set_slope(float(kwargs['slope'])) elif 'angle' in kwargs: # case C self._set_angle(normalize_angle(float(kwargs['angle']))) if self.is_vertical: self._x = p1x if not self.is_vertical: # y0 is the y-coordinate of this ray at x-coordinate == 0 self._y0 = p1y - self.slope * p1x
def __init__(self, point1, point2=None, **kwargs): self._vertical = False self.places = 7 p1x = float(point1[XCOORD]) p1y = float(point1[YCOORD]) if point2 is not None: # case A # normalize point order to assure consist signs for slopes # +slope goes up and -slope goes down self._slope = 0 self._angle = 0 p2x = float(point2[XCOORD]) p2y = float(point2[YCOORD]) if p1x > p2x : p1x, p2x = p2x, p1x p1y, p2y = p2y, p1y dx = p2x - p1x dy = p2y - p1y if dx == 0. : # line is vertical self._x = p1x self._set_angle(HALF_PI) else : self._set_slope(dy/dx) elif 'slope' in kwargs: # case B self._set_slope(float(kwargs['slope'])) elif 'angle' in kwargs: # case C self._set_angle(normalize_angle(float(kwargs['angle']))) if self.is_vertical: self._x = p1x if not self.is_vertical: # y0 is the y-coordinate of this ray at x-coordinate == 0 self._y0 = p1y - self.slope * p1x
def _set_slope(self, slope): # private self._slope = slope self._angle = normalize_angle(math.atan(slope))