本文整理汇总了C++中ccw函数的典型用法代码示例。如果您正苦于以下问题:C++ ccw函数的具体用法?C++ ccw怎么用?C++ ccw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ccw函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ccw_cmp
int ccw_cmp(const void *a, const void *b){
Point *p1 = (Point *)a;
Point *p2 = (Point *)b;
if (ccw(start_p, *p1, *p2) == CCW) return -1;
if (ccw(start_p, *p2, *p1) == CCW) return 1;
return 0;
}
示例2: ccw
bool CLine2d::intersects(const CLine2d& otherLine) const
{
bool retval = false;
if (getExtent().intersects(otherLine.getExtent()))
{
int ccw0 = ccw(otherLine.m_p0) * ccw(otherLine.m_p1);
if (ccw0 == 0)
{
retval = true;
}
else
{
int ccw1 = otherLine.ccw(m_p0) * otherLine.ccw(m_p1);
if (ccw1 == 0)
{
retval = true;
}
else
{
retval = ((ccw0 < 0) && (ccw1 < 0));
}
}
}
return retval;
}
示例3: intersect
bool intersect( Line line1, Line line2 )
{
return (( ccw(line1.p1, line1.p2, line2.p1)
* ccw(line1.p1, line1.p2, line2.p2)) <= 0)
&& (( ccw(line2.p1, line2.p2, line1.p1)
* ccw(line2.p1, line2.p2, line1.p2)) <= 0);
}
示例4: main
int main()
{
srand(time(NULL));
//points = (point*) calloc(points_count, sizeof(struct point));
struct point * hull = (point*) calloc(points_count, sizeof(struct point));
rand_points(&points, points_count, dimxy);
qsort(points, points_count, sizeof(struct point), cmp_points);
int hind = 0;
for(int i=0; i < points_count; i++)
{
while (hind >= 2 && !ccw(hull[hind-2], hull[hind-1], points[i])) {hind--;}
hull[hind++] = points[i];
}
for(int i = points_count-2, lim = hind+1; i >= 0; --i)
{
while (hind >= lim && !ccw(hull[hind-2], hull[hind-1], points[i])) {hind--;}
hull[hind++] = points[i];
}
/*printf("hull:");
for (int i=0; i < hind; i++) { printf("(%d,%d),", hull[i].x, hull[i].y); }
printf("\n");*/
void * r = realloc(hull, sizeof(struct point) * hind);
int ret = plot(points, points_count, hull, hind);
free(points);
}
示例5: xsort
/**
* compute the convex hull of a collection of Points
*
* @param points the points as a Vector2 array.
* @param pointsLength the number of vertices of the polygon.
* @param retPoly pre allocated array of floats to put the vertices
* @return the number of points in the polygon 0 if no intersection
*/
int SpotShadow::hull(Vector2* points, int pointsLength, Vector2* retPoly) {
xsort(points, pointsLength);
int n = pointsLength;
Vector2 lUpper[n];
lUpper[0] = points[0];
lUpper[1] = points[1];
int lUpperSize = 2;
for (int i = 2; i < n; i++) {
lUpper[lUpperSize] = points[i];
lUpperSize++;
while (lUpperSize > 2 && !ccw(
lUpper[lUpperSize - 3].x, lUpper[lUpperSize - 3].y,
lUpper[lUpperSize - 2].x, lUpper[lUpperSize - 2].y,
lUpper[lUpperSize - 1].x, lUpper[lUpperSize - 1].y)) {
// Remove the middle point of the three last
lUpper[lUpperSize - 2].x = lUpper[lUpperSize - 1].x;
lUpper[lUpperSize - 2].y = lUpper[lUpperSize - 1].y;
lUpperSize--;
}
}
Vector2 lLower[n];
lLower[0] = points[n - 1];
lLower[1] = points[n - 2];
int lLowerSize = 2;
for (int i = n - 3; i >= 0; i--) {
lLower[lLowerSize] = points[i];
lLowerSize++;
while (lLowerSize > 2 && !ccw(
lLower[lLowerSize - 3].x, lLower[lLowerSize - 3].y,
lLower[lLowerSize - 2].x, lLower[lLowerSize - 2].y,
lLower[lLowerSize - 1].x, lLower[lLowerSize - 1].y)) {
// Remove the middle point of the three last
lLower[lLowerSize - 2] = lLower[lLowerSize - 1];
lLowerSize--;
}
}
// output points in CW ordering
const int total = lUpperSize + lLowerSize - 2;
int outIndex = total - 1;
for (int i = 0; i < lUpperSize; i++) {
retPoly[outIndex] = lUpper[i];
outIndex--;
}
for (int i = 1; i < lLowerSize - 1; i++) {
retPoly[outIndex] = lLower[i];
outIndex--;
}
// TODO: Add test harness which verify that all the points are inside the hull.
return total;
}
示例6: intersect
int intersect(Line l1, Line l2)
{
// The following expression evaluates true if both endpoints of each line
// are on different sides of the other:
return ((ccw(l1.p1, l1.p2, l2.p1)*ccw(l1.p1, l1.p2, l2.p2)) <= 0)
&& ((ccw(l2.p1, l2.p2, l1.p1)*ccw(l2.p1, l2.p2, l1.p2)) <= 0);
}
示例7: return
bool Geometry::checkIntersectionOfLines(
const Vector2<>& l1p1,
const Vector2<>& l1p2,
const Vector2<>& l2p1,
const Vector2<>& l2p2)
{
return (((ccw(l1p1, l1p2, l2p1) * ccw(l1p1, l1p2, l2p2)) <= 0)
&& ((ccw(l2p1, l2p2, l1p1) * ccw(l2p1, l2p2, l1p2)) <= 0));
}
示例8: ConvexCut
VP ConvexCut(const VP &ps, L l) {
VP Q;
for (int i = 0; i < (int)ps.size(); i++) {
P A = ps[i], B = ps[(i+1)%ps.size()];
if (ccw(l.a, l.b, A) != -1) Q.push_back(A);
if (ccw(l.a, l.b, A) * ccw(l.a, l.b, B) < 0)
Q.push_back(is_ll((L){A, B}, l));
}
return Q;
}
示例9: spsorty
// Recursive Delaunay Triangulation Procedure
// Contains modifications for axis-switching division.
void CDelaunay::build(int lo, int hi, EdgePointer *le, EdgePointer *re, int rows)
{
EdgePointer a, b, c, ldo, rdi, ldi, rdo, maxx, minx;
int split, lowrows;
int low, high;
SitePointer s1, s2, s3;
low = lo;
high = hi;
if ( low < (high-2) ) {
// more than three elements; do recursion
minx = sp[low];
maxx = sp[high];
if (rows == 1) { // time to switch axis of division
spsorty( sp, low, high);
rows = 65536;
}
lowrows = rows/2;
split = low - 1 + (int)
(0.5 + ((double)(high-low+1) * ((double)lowrows / (double)rows)));
build( low, split, &ldo, &ldi, lowrows );
build( split+1, high, &rdi, &rdo, (rows-lowrows) );
doMerge(&ldo, ldi, rdi, &rdo);
while (orig(ldo) != minx) {
ldo = rprev(ldo);
}
while (orig(rdo) != maxx) {
rdo = (SitePointer) lprev(rdo);
}
*le = ldo;
*re = rdo;
}
else if (low >= (high - 1)) { // two or one points
a = makeEdge(sp[low], sp[high]);
*le = a;
*re = (EdgePointer) sym(a);
} else { // three points
// 3 cases: triangles of 2 orientations, and 3 points on a line
a = makeEdge((s1 = sp[low]), (s2 = sp[low+1]));
b = makeEdge(s2, (s3 = sp[high]));
splice((EdgePointer) sym(a), b);
if (ccw(s1, s3, s2)) {
c = connectLeft(b, a);
*le = (EdgePointer) sym(c);
*re = c;
} else {
*le = a;
*re = (EdgePointer) sym(b);
if (ccw(s1, s2, s3)) {
// not colinear
c = connectLeft(b, a);
}
}
}
}
示例10: convex_cut
// 左側切除
Polygon convex_cut(const Polygon &p, const Line &l){
Polygon res;
for(int i = 0; i < p.size(); ++i){
P a = curr(p,i), b = next(p,i);
Line tl = Line(a, b);
if(ccw(l[0], l[1], a) != -1) res.push_back(a);
if(ccw(l[0], l[1], a) * ccw(l[0], l[1], b) < 0)
res.push_back(crosspointLL(tl, l));
}
return res;
}
示例11: convex_hull
Polygon convex_hull(vector<Point> ps) {
int n = ps.size(), k = 0;
sort(begin(ps), end(ps), comp);
Polygon ch(2 * n);
for (int i = 0; i < n; ch[k++] = ps[i++])
while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
ch.resize(k - 1);
return ch;
}
示例12: ConvexHull
VP ConvexHull(VP ps) {
int n = ps.size();
int k = 0;
sort(ps.begin(), ps.end());
VP ch(2 * n);
for (int i = 0; i < n; ch[k++] = ps[i++])
while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
ch.resize(k - 1);
return ch;
}
示例13: convexCut
Polygon convexCut(const Polygon &P, const Line &l) {
Polygon Q;
for (int i = 0; i < (int)P.size(); i++) {
Point A = CURR(P, i), B = NEXT(P, i);
if (ccw(l[0], l[1], A) != -1) {
Q.push_back(A);
}
if (ccw(l[0], l[1], A) * ccw(l[0], l[1], B) < 0) {
Q.push_back(crosspointSS(Line(A, B), l));
}
}
return Q;
}
示例14: pointCount
bool KarbonCalligraphicShape::flipDetected(const QPointF &p1, const QPointF &p2)
{
// detect the flip caused by the angle changing 180 degrees
// thus detect the boundary crossing
int index = pointCount() / 2;
QPointF last1 = pointByIndex(KoPathPointIndex(0, index - 1))->point();
QPointF last2 = pointByIndex(KoPathPointIndex(0, index))->point();
int sum1 = std::abs(ccw(p1, p2, last1) + ccw(p1, last2, last1));
int sum2 = std::abs(ccw(p2, p1, last2) + ccw(p2, last1, last2));
// if there was a flip
return sum1 < 2 && sum2 < 2;
}
示例15: line_segment_distance
double line_segment_distance(L(a,b), L(c,d)) {
double x = INFINITY;
if (abs(a - b) < EPS && abs(c - d) < EPS) x = abs(a - c);
else if (abs(a - b) < EPS) x = abs(a - closest_point(c, d, a, true));
else if (abs(c - d) < EPS) x = abs(c - closest_point(a, b, c, true));
else if ((ccw(a, b, c) < 0) != (ccw(a, b, d) < 0) &&
(ccw(c, d, a) < 0) != (ccw(c, d, b) < 0)) x = 0;
else {
x = min(x, abs(a - closest_point(c,d, a, true)));
x = min(x, abs(b - closest_point(c,d, b, true)));
x = min(x, abs(c - closest_point(a,b, c, true)));
x = min(x, abs(d - closest_point(a,b, d, true)));
}
return x;
}