Lagrange
Loading...
Searching...
No Matches
nrosy_utils.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
16#include <cmath>
17#include <limits>
18
19namespace lagrange::polyddg {
20
25template <typename Scalar>
26Eigen::Matrix<Scalar, 2, 1> nrosy_encode(const Eigen::Matrix<Scalar, 2, 1>& v, int n)
27{
28 Scalar r = v.norm();
29 if (r < std::numeric_limits<Scalar>::epsilon()) return v;
30
31 Scalar c = v(0) / r, s = v(1) / r;
32 Scalar re = Scalar(1), im = Scalar(0);
33 for (int k = 0; k < n; ++k) {
34 Scalar new_re = re * c - im * s;
35 Scalar new_im = re * s + im * c;
36 re = new_re;
37 im = new_im;
38 }
39 return {r * re, r * im};
40}
41
46template <typename Scalar>
47Eigen::Matrix<Scalar, 2, 1> nrosy_decode(const Eigen::Matrix<Scalar, 2, 1>& v, int n)
48{
49 Scalar r = v.norm();
50 if (r < std::numeric_limits<Scalar>::epsilon()) return v;
51
52 Scalar phi = std::atan2(v(1), v(0));
53 Scalar theta = phi / static_cast<Scalar>(n);
54 return {r * std::cos(theta), r * std::sin(theta)};
55}
56
57} // namespace lagrange::polyddg
@ Scalar
Mesh attribute must have exactly 1 channel.
Definition AttributeFwd.h:56