line2d.cpp
资源名称:package.rar [点击查看]
上传用户:chinasdcnc
上传日期:2022-07-02
资源大小:2702k
文件大小:1k
源码类别:
分形几何
开发平台:
Visual C++
- //
- // Delaunay Triangulation
- //
- // Homework of CG lesson (Fall 2009) in Tsinghua University.
- // All rights reserved.
- //
- // temp include, delete later if necessary
- #include "stdafx.h"
- #include "line2d.h"
- // User headers
- #include "base.h"
- Line2d::Line2d(void)
- :a(1.0), b(1.0), c(1.0)
- {
- }
- Line2d::Line2d(const Point2d& p1, const Point2d& p2)
- {
- a = p2.y - p1.y;
- b = p1.x - p2.x;
- c = p1.y * (p2.x - p1.x) - p1.x * (p2.y - p1.y);
- }
- double Line2d::eval(const Point2d& p) const
- {
- return (a * p.x + b * p.y + c);
- }
- int Line2d::classify(const Point2d& p) const
- {
- double d = eval(p);
- if (d < -TOLERANCE)
- return -1;
- else if (d > TOLERANCE)
- return 1;
- else
- return 0;
- }