Lagrange
compute_barycentric_coordinates.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/common.h>
15
16namespace lagrange {
17
18template <typename PointType>
19auto compute_barycentric_coordinates(
20 const Eigen::MatrixBase<PointType>& v0,
21 const Eigen::MatrixBase<PointType>& v1,
22 const Eigen::MatrixBase<PointType>& v2,
23 const Eigen::MatrixBase<PointType>& p) -> Eigen::Matrix<typename PointType::Scalar, 3, 1>
24{
25 using Scalar = typename PointType::Scalar;
26 const auto dim = p.size();
27 Eigen::Matrix<Scalar, 3, 3> M;
28 M.setZero();
29 M.block(0, 0, dim, 1) = v0;
30 M.block(0, 1, dim, 1) = v1;
31 M.block(0, 2, dim, 1) = v2;
32 Eigen::Matrix<Scalar, 3, 1> rhs;
33 rhs.setZero();
34 rhs.segment(0, dim) = p;
35 return (M.inverse() * rhs).eval();
36}
37
38
39} // namespace lagrange
Main namespace for Lagrange.
Definition: AABBIGL.h:30