-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrLine2D.cpp
62 lines (59 loc) · 1.08 KB
/
rLine2D.cpp
1
//#include <iostream.h>#include "rPoint2D.h"#include "rLine2D.h"#include <ostream>#include <iostream>rLine2D::rLine2D (double slope,double intercept){ m = slope; b = intercept;}rLine2D::rLine2D (rPoint2D p0,rPoint2D p1){ m = (p1.y-p0.y)/(p1.x-p0.x); b = p0.y - m*p0.x;}rLine2D::rLine2D (double x0,double y0,double x1, double y1){ m = (y1-y0)/(x1-x0); b = y0 - m*x0;}rLine2D& rLine2D::operator=(rLine2D p){ m = p.m; b = p.b; return (*this);}int rLine2D::operator==(rLine2D p){ if (m == p.m && b == p.b ) return (1); else return (0);}std::ostream& operator<<(std::ostream& os, rLine2D& p){ os << "[y = "<< p.m <<"*x + "<<p.b<<']'; return os;} void rLine2D::set(rPoint2D p0, rPoint2D p1){ m = (p1.y-p0.y)/(p1.x-p0.x); b = p0.y - m*p0.x;}double rLine2D::y(double x) { return m*x + b;}double rLine2D::x(double y) { return (y-b)/m;}int rLine2D::sameside (rPoint2D p,rPoint2D q) { double result1=m*p.x+b; double result2=m*q.x+b; return (p.y <= result1) == (q.y <= result2) || (p.y >= result1) == (q.y >= result2) ;}