Lagrange
Loading...
Searching...
No Matches
point_on_segment.h
1/*
2 * Copyright 2020 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/api.h>
15#include <Eigen/Core>
16
17namespace lagrange {
18
19namespace internal {
20
22bool LA_CORE_API
23point_on_segment_2d(const Eigen::Vector2d& p, const Eigen::Vector2d& a, const Eigen::Vector2d& b);
24
26bool LA_CORE_API
27point_on_segment_3d(const Eigen::Vector3d& p, const Eigen::Vector3d& a, const Eigen::Vector3d& b);
28
29} // namespace internal
30
44template <typename PointType>
46 const Eigen::MatrixBase<PointType>& p,
47 const Eigen::MatrixBase<PointType>& a,
48 const Eigen::MatrixBase<PointType>& b)
49{
50 if (p.size() == 2 && a.size() == 2 && b.size() == 2) {
51 Eigen::Vector2d p2d(static_cast<double>(p.x()), static_cast<double>(p.y()));
52 Eigen::Vector2d a2d(static_cast<double>(a.x()), static_cast<double>(a.y()));
53 Eigen::Vector2d b2d(static_cast<double>(b.x()), static_cast<double>(b.y()));
54 return internal::point_on_segment_2d(p2d, a2d, b2d);
55 } else if (p.size() == 3 && a.size() == 3 && b.size() == 3) {
56 Eigen::Vector3d p3d(
57 static_cast<double>(p[0]),
58 static_cast<double>(p[1]),
59 static_cast<double>(p[2]));
60 Eigen::Vector3d a3d(
61 static_cast<double>(a[0]),
62 static_cast<double>(a[1]),
63 static_cast<double>(a[2]));
64 Eigen::Vector3d b3d(
65 static_cast<double>(b[0]),
66 static_cast<double>(b[1]),
67 static_cast<double>(b[2]));
68 return internal::point_on_segment_3d(p3d, a3d, b3d);
69 } else {
70 throw std::runtime_error("Incompatible types");
71 }
72}
73
74} // namespace lagrange
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition attribute_string_utils.h:21
Main namespace for Lagrange.
bool point_on_segment(const Eigen::MatrixBase< PointType > &p, const Eigen::MatrixBase< PointType > &a, const Eigen::MatrixBase< PointType > &b)
Test if a point lies exactly on a segment [a,b] using exact predicates.
Definition point_on_segment.h:45