|
| 1 | +// Copyright 2024 Taiga Takano |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef NDTCPP_MATRIX_UTIL_HPP_ |
| 16 | +#define NDTCPP_MATRIX_UTIL_HPP_ |
| 17 | + |
| 18 | +#include "type.hpp" |
| 19 | + |
| 20 | +namespace ndtcpp |
| 21 | +{ |
| 22 | + auto operator*(const mat3x3& mat1, const mat3x3& mat2) |
| 23 | + { |
| 24 | + mat3x3 result; |
| 25 | + result.a = mat1.a * mat2.a + mat1.b * mat2.d + mat1.c * mat2.g; |
| 26 | + result.b = mat1.a * mat2.b + mat1.b * mat2.e + mat1.c * mat2.h; |
| 27 | + result.c = mat1.a * mat2.c + mat1.b * mat2.f + mat1.c * mat2.i; |
| 28 | + |
| 29 | + result.d = mat1.d * mat2.a + mat1.e * mat2.d + mat1.f * mat2.g; |
| 30 | + result.e = mat1.d * mat2.b + mat1.e * mat2.e + mat1.f * mat2.h; |
| 31 | + result.f = mat1.d * mat2.c + mat1.e * mat2.f + mat1.f * mat2.i; |
| 32 | + |
| 33 | + result.g = mat1.g * mat2.a + mat1.h * mat2.d + mat1.i * mat2.g; |
| 34 | + result.h = mat1.g * mat2.b + mat1.h * mat2.e + mat1.i * mat2.h; |
| 35 | + result.i = mat1.g * mat2.c + mat1.h * mat2.f + mat1.i * mat2.i; |
| 36 | + return result; |
| 37 | + } |
| 38 | + |
| 39 | + auto operator*(const mat3x3& mat, const point3& vec) |
| 40 | + { |
| 41 | + point3 result; |
| 42 | + result.x = mat.a * vec.x + mat.b * vec.y + mat.c * vec.z; |
| 43 | + result.y = mat.d * vec.x + mat.e * vec.y + mat.f * vec.z; |
| 44 | + result.z = mat.g * vec.x + mat.h * vec.y + mat.i * vec.z; |
| 45 | + return result; |
| 46 | + } |
| 47 | + |
| 48 | + auto operator+=(mat3x3& mat1, const mat3x3& mat2) |
| 49 | + { |
| 50 | + mat1.a += mat2.a; |
| 51 | + mat1.b += mat2.b; |
| 52 | + mat1.c += mat2.c; |
| 53 | + |
| 54 | + mat1.d += mat2.d; |
| 55 | + mat1.e += mat2.e; |
| 56 | + mat1.f += mat2.f; |
| 57 | + |
| 58 | + mat1.g += mat2.g; |
| 59 | + mat1.h += mat2.h; |
| 60 | + mat1.i += mat2.i; |
| 61 | + } |
| 62 | + |
| 63 | + auto operator+=(ndtcpp::point3& point1, const ndtcpp::point3& point2){ |
| 64 | + point1.x += point2.x; |
| 65 | + point1.y += point2.y; |
| 66 | + point1.z += point2.z; |
| 67 | + } |
| 68 | +} // namespace ndtcpp |
| 69 | + |
| 70 | +#endif // NDTCPP_MATRIX_UTIL_HPP_ |
0 commit comments