Lagrange
Loading...
Searching...
No Matches
compute_normal_cotransform.h
1/*
2 * Copyright 2026 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 <Eigen/Core>
15#include <Eigen/Geometry>
16
17namespace lagrange {
18
21
37template <typename Scalar>
38Eigen::Matrix3<Scalar> compute_normal_cotransform(
39 const Eigen::Transform<Scalar, 3, Eigen::Affine>& transform)
40{
41 const auto& matrix = transform.linear();
42 auto minor2x2 = [&](int i, int j) -> Scalar {
43 const int i1 = (i == 0 ? 1 : 0);
44 const int i2 = (i == 2 ? 1 : 2);
45 const int j1 = (j == 0 ? 1 : 0);
46 const int j2 = (j == 2 ? 1 : 2);
47 return matrix(i1, j1) * matrix(i2, j2) - matrix(i1, j2) * matrix(i2, j1);
48 };
49
50 Eigen::Matrix3<Scalar> result;
51 for (int i = 0; i < 3; ++i) {
52 for (int j = 0; j < 3; ++j) {
53 result(i, j) = ((i + j) % 2 == 0 ? Scalar(1) : Scalar(-1)) * minor2x2(i, j);
54 }
55 }
56 return result;
57}
58
69template <typename Scalar>
70Eigen::Matrix2<Scalar> compute_normal_cotransform(
71 const Eigen::Transform<Scalar, 2, Eigen::Affine>& transform)
72{
73 const auto& matrix = transform.linear();
74 Eigen::Matrix2<Scalar> result;
75 result(0, 0) = matrix(1, 1);
76 result(0, 1) = -matrix(1, 0);
77 result(1, 0) = -matrix(0, 1);
78 result(1, 1) = matrix(0, 0);
79 return result;
80}
81
83
84} // namespace lagrange
@ Scalar
Mesh attribute must have exactly 1 channel.
Definition AttributeFwd.h:56
Eigen::Matrix3< Scalar > compute_normal_cotransform(const Eigen::Transform< Scalar, 3, Eigen::Affine > &transform)
Computes the normal (cotransform) matrix for a 3D affine transform.
Definition compute_normal_cotransform.h:38
Main namespace for Lagrange.