Coverage Control Library
Loading...
Searching...
No Matches
geometry_utils.cuh
Go to the documentation of this file.
1/*
2 * This file is part of the CoverageControl library
3 *
4 * Author: Saurav Agarwal
5 * Contact: sauravag@seas.upenn.edu, agr.saurav1@gmail.com
6 * Repository: https://github.com/KumarRobotics/CoverageControl
7 *
8 * Copyright (c) 2024, Saurav Agarwal
9 *
10 * The CoverageControl library is free software: you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or (at your
13 * option) any later version.
14 *
15 * The CoverageControl library is distributed in the hope that it will be
16 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18 * Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * CoverageControl library. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30#ifndef CPPSRC_CORE_INCLUDE_COVERAGECONTROL_CUDA_GEOMETRY_UTILS_CUH_
31#define CPPSRC_CORE_INCLUDE_COVERAGECONTROL_CUDA_GEOMETRY_UTILS_CUH_
32
33#include <cuda_runtime.h>
34
35/* #include "CoverageControl/extern/cuda_helpers/helper_cuda.h" */
36
37namespace CoverageControl {
44__host__ __device__ int Orientation(float2 const &p, float2 const &q,
45 float2 const &r) {
46 float2 qp{q.x - p.x, q.y - p.y};
47 float2 rp{r.x - p.x, r.y - p.y};
48 float cross_prod1 = qp.x * rp.y;
49 float cross_prod2 = qp.y * rp.x;
50 if (cross_prod1 > cross_prod2) return 1;
51 if (cross_prod1 < cross_prod2) return -1;
52 return 0;
53}
54
59__host__ __device__ bool IsPointInMonotonePolygon(float *x, float *y, int sz,
60 float2 const &r) {
61 bool left = false;
62 bool right = false;
63 for (int ct = 0; ct < sz; ++ct) {
64 int ctp1 = ct + 1;
65 if (ctp1 == sz) {
66 ctp1 = 0;
67 }
68 float yct = y[ct];
69 float yctp1 = y[ctp1];
70 /* printf("Edge: %f, %f, %f, %f\n", x[ct], yct, x[ctp1], yctp1); */
71 float2 p, q;
72 if (yct < yctp1) {
73 if (r.y < yct or r.y > yctp1) {
74 continue;
75 }
76 p = float2{x[ct], yct};
77 q = float2{x[ctp1], yctp1};
78 } else {
79 if (r.y < yctp1 or r.y > yct) {
80 continue;
81 }
82 q = float2{x[ct], yct};
83 p = float2{x[ctp1], yctp1};
84 }
85 int orientation = Orientation(p, q, r);
86 /* printf("orientation: %d\n", orientation); */
87 if (orientation == 0) {
88 return true;
89 }
90 if (orientation == 1) {
91 left = true;
92 }
93 if (orientation == -1) {
94 right = true;
95 }
96 if ((left & right)) {
97 return true;
98 }
99 }
100 return false;
101}
102} /* namespace CoverageControl */
103
104#endif // CPPSRC_CORE_INCLUDE_COVERAGECONTROL_CUDA_GEOMETRY_UTILS_CUH_
Namespace for the CoverageControl library.
__host__ __device__ int Orientation(float2 const &p, float2 const &q, float2 const &r)
__host__ __device__ bool IsPointInMonotonePolygon(float *x, float *y, int sz, float2 const &r)