bgc-net/Geometry/DPMatrix2x3.cs

310 lines
11 KiB
C#

/*
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
/*
* Author: Andrey Pokidov
* Date: 11 Nov 2024
*/
namespace Geometry
{
public struct DPMatrix2x3
{
public double r1c1, r1c2;
public double r2c1, r2c2;
public double r3c1, r3c2;
public DPMatrix2x3()
{
this.r1c1 = 0.0;
this.r1c2 = 0.0;
this.r2c1 = 0.0;
this.r2c2 = 0.0;
this.r3c1 = 0.0;
this.r3c2 = 0.0;
}
public DPMatrix2x3(in DPMatrix2x3 matrix)
{
this.r1c1 = matrix.r1c1;
this.r1c2 = matrix.r1c2;
this.r2c1 = matrix.r2c1;
this.r2c2 = matrix.r2c2;
this.r3c1 = matrix.r3c1;
this.r3c2 = matrix.r3c2;
}
public DPMatrix2x3(in SPMatrix2x3 matrix)
{
this.r1c1 = matrix.r1c1;
this.r1c2 = matrix.r1c2;
this.r2c1 = matrix.r2c1;
this.r2c2 = matrix.r2c2;
this.r3c1 = matrix.r3c1;
this.r3c2 = matrix.r3c2;
}
public DPMatrix2x3(in DPMatrix3x2 matrix)
{
this.r1c1 = matrix.r1c1;
this.r1c2 = matrix.r2c1;
this.r2c1 = matrix.r1c2;
this.r2c2 = matrix.r2c2;
this.r3c1 = matrix.r1c3;
this.r3c2 = matrix.r2c3;
}
public DPMatrix2x3(in SPMatrix3x2 matrix)
{
this.r1c1 = matrix.r1c1;
this.r1c2 = matrix.r2c1;
this.r2c1 = matrix.r1c2;
this.r2c2 = matrix.r2c2;
this.r3c1 = matrix.r1c3;
this.r3c2 = matrix.r2c3;
}
public void Reset()
{
this.r1c1 = 0.0;
this.r1c2 = 0.0;
this.r2c1 = 0.0;
this.r2c2 = 0.0;
this.r3c1 = 0.0;
this.r3c2 = 0.0;
}
public void SetValues(in DPMatrix2x3 matrix)
{
this.r1c1 = matrix.r1c1;
this.r1c2 = matrix.r1c2;
this.r2c1 = matrix.r2c1;
this.r2c2 = matrix.r2c2;
this.r3c1 = matrix.r3c1;
this.r3c2 = matrix.r3c2;
}
public void SetValues(in SPMatrix2x3 matrix)
{
this.r1c1 = matrix.r1c1;
this.r1c2 = matrix.r1c2;
this.r2c1 = matrix.r2c1;
this.r2c2 = matrix.r2c2;
this.r3c1 = matrix.r3c1;
this.r3c2 = matrix.r3c2;
}
public void SetTransposed(in DPMatrix3x2 matrix)
{
this.r1c1 = matrix.r1c1;
this.r1c2 = matrix.r2c1;
this.r2c1 = matrix.r1c2;
this.r2c2 = matrix.r2c2;
this.r3c1 = matrix.r1c3;
this.r3c2 = matrix.r2c3;
}
public void SetTransposed(in SPMatrix3x2 matrix)
{
this.r1c1 = matrix.r1c1;
this.r1c2 = matrix.r2c1;
this.r2c1 = matrix.r1c2;
this.r2c2 = matrix.r2c2;
this.r3c1 = matrix.r1c3;
this.r3c2 = matrix.r2c3;
}
public void SetRow1(double c1, double c2)
{
this.r1c1 = c1;
this.r1c2 = c2;
}
public void SetRow2(double c1, double c2)
{
this.r2c1 = c1;
this.r2c2 = c2;
}
public void SetRow3(double c1, double c2)
{
this.r3c1 = c1;
this.r3c2 = c2;
}
public void SetColumn1(double r1, double r2, double r3)
{
this.r1c1 = r1;
this.r2c1 = r2;
this.r3c1 = r3;
}
public void SetColumn2(double r1, double r2, double r3)
{
this.r1c2 = r1;
this.r2c2 = r2;
this.r3c2 = r3;
}
public static void Add(in DPMatrix2x3 matrix1, in DPMatrix2x3 matrix2, out DPMatrix2x3 sum)
{
sum.r1c1 = matrix1.r1c1 + matrix2.r1c1;
sum.r1c2 = matrix1.r1c2 + matrix2.r1c2;
sum.r2c1 = matrix1.r2c1 + matrix2.r2c1;
sum.r2c2 = matrix1.r2c2 + matrix2.r2c2;
sum.r3c1 = matrix1.r3c1 + matrix2.r3c1;
sum.r3c2 = matrix1.r3c2 + matrix2.r3c2;
}
public static void Subtract(in DPMatrix2x3 minuend, in DPMatrix2x3 subtrahend, out DPMatrix2x3 difference)
{
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
difference.r2c1 = minuend.r2c1 - subtrahend.r2c1;
difference.r2c2 = minuend.r2c2 - subtrahend.r2c2;
difference.r3c1 = minuend.r3c1 - subtrahend.r3c1;
difference.r3c2 = minuend.r3c2 - subtrahend.r3c2;
}
public static void Multiply(in DPMatrix2x3 multiplicand, double multiplier, out DPMatrix2x3 product)
{
product.r1c1 = multiplicand.r1c1 * multiplier;
product.r1c2 = multiplicand.r1c2 * multiplier;
product.r2c1 = multiplicand.r2c1 * multiplier;
product.r2c2 = multiplicand.r2c2 * multiplier;
product.r3c1 = multiplicand.r3c1 * multiplier;
product.r3c2 = multiplicand.r3c2 * multiplier;
}
public static void Divide(in DPMatrix2x3 dividend, double divisor, out DPMatrix2x3 quotient)
{
quotient.r1c1 = dividend.r1c1 / divisor;
quotient.r1c2 = dividend.r1c2 / divisor;
quotient.r2c1 = dividend.r2c1 / divisor;
quotient.r2c2 = dividend.r2c2 / divisor;
quotient.r3c1 = dividend.r3c1 / divisor;
quotient.r3c2 = dividend.r3c2 / divisor;
}
public static void GetWeightedSum2(
double weight1, in DPMatrix2x3 matrix1,
double weight2, in DPMatrix2x3 matrix2,
out DPMatrix2x3 sum)
{
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
sum.r2c1 = matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2;
sum.r2c2 = matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2;
sum.r3c1 = matrix1.r3c1 * weight1 + matrix2.r3c1 * weight2;
sum.r3c2 = matrix1.r3c2 * weight1 + matrix2.r3c2 * weight2;
}
public static void GetWeightedSum3(
double weight1, in DPMatrix2x3 matrix1,
double weight2, in DPMatrix2x3 matrix2,
double weight3, in DPMatrix2x3 matrix3,
out DPMatrix2x3 sum)
{
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
sum.r2c1 = matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2 + matrix3.r2c1 * weight3;
sum.r2c2 = matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2 + matrix3.r2c2 * weight3;
sum.r3c1 = matrix1.r3c1 * weight1 + matrix2.r3c1 * weight2 + matrix3.r3c1 * weight3;
sum.r3c2 = matrix1.r3c2 * weight1 + matrix2.r3c2 * weight2 + matrix3.r3c2 * weight3;
}
public static void GetWeightedSum4(
double weight1, in DPMatrix2x3 matrix1,
double weight2, in DPMatrix2x3 matrix2,
double weight3, in DPMatrix2x3 matrix3,
double weight4, in DPMatrix2x3 matrix4,
out DPMatrix2x3 sum)
{
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
sum.r2c1 = (matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2) + (matrix3.r2c1 * weight3 + matrix4.r2c1 * weight4);
sum.r2c2 = (matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2) + (matrix3.r2c2 * weight3 + matrix4.r2c2 * weight4);
sum.r3c1 = (matrix1.r3c1 * weight1 + matrix2.r3c1 * weight2) + (matrix3.r3c1 * weight3 + matrix4.r3c1 * weight4);
sum.r3c2 = (matrix1.r3c2 * weight1 + matrix2.r3c2 * weight2) + (matrix3.r3c2 * weight3 + matrix4.r3c2 * weight4);
}
public static void GetWeightedSum5(
double weight1, in DPMatrix2x3 matrix1,
double weight2, in DPMatrix2x3 matrix2,
double weight3, in DPMatrix2x3 matrix3,
double weight4, in DPMatrix2x3 matrix4,
double weight5, in DPMatrix2x3 matrix5,
out DPMatrix2x3 sum)
{
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
sum.r2c1 = (matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2) + (matrix3.r2c1 * weight3 + matrix4.r2c1 * weight4) + matrix5.r2c1 * weight5;
sum.r2c2 = (matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2) + (matrix3.r2c2 * weight3 + matrix4.r2c2 * weight4) + matrix5.r2c2 * weight5;
sum.r3c1 = (matrix1.r3c1 * weight1 + matrix2.r3c1 * weight2) + (matrix3.r3c1 * weight3 + matrix4.r3c1 * weight4) + matrix5.r3c1 * weight5;
sum.r3c2 = (matrix1.r3c2 * weight1 + matrix2.r3c2 * weight2) + (matrix3.r3c2 * weight3 + matrix4.r3c2 * weight4) + matrix5.r3c2 * weight5;
}
public static void GetRightProduct(in DPMatrix2x3 matrix, in DPVector2 vector, out DPVector3 result)
{
result.x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2;
result.x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2;
result.x3 = matrix.r3c1 * vector.x1 + matrix.r3c2 * vector.x2;
}
public static void GetLeftProduct(in DPVector3 vector, in DPMatrix2x3 matrix, out DPVector2 result)
{
result.x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1 + vector.x3 * matrix.r3c1;
result.x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2 + vector.x3 * matrix.r3c2;
}
}
}