Files
stgsharp/源代码/StgSharp/Linear/Plain.cs
T

58 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using StgSharp.Geometries;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Linear
{
public unsafe class Plain
{
internal vec3d vec1;
internal vec3d vec2;
internal float a;
internal float b;
internal float c;
internal readonly float d = -1 ;
public Plain(vec3d origin, vec3d v1, vec3d v2)
{
vec1 = v1 - v2 * (v1.Y/v2.Y); //计算平面在xz平面上的方向投影
vec2 = v2 - vec1 * (v2.X/v1.X); //计算平面在yz平面上的方向投影
//|origin|-k1*|vec1|-k2*|vec2|计算c;
c = origin.Z - vec1.Z * (origin.X / vec1.X) - vec2.Z * (origin.Y / vec2.Y);
//根据c和对应的方向矢量计算a和b
a = vec1.X * (vec1.Z / c);
b = vec2.Y * (vec2.Z / c);
a = 1 / a;
b = 1 / b;
c = 1 / c;
}
public Plain(Point p1, Point p2, Point p3)
{
vec3d origin = p1._position;
vec3d v1 = p2._position - origin;
vec3d v2 = p3._position - origin;
vec1 = v1 - v2 * (v1.Y / v2.Y); //计算平面在xz平面上的方向投影
vec2 = v2 - vec1 * (v2.X / v1.X); //计算平面在yz平面上的方向投影
//|origin|-k1*|vec1|-k2*|vec2|计算c;
c = origin.Z - vec1.Z * (origin.X / vec1.X) - vec2.Z * (origin.Y / vec2.Y);
//根据c和对应的方向矢量计算a和b
a = vec1.X * (vec1.Z / c);
b = vec2.Y * (vec2.Z / c);
a = 1 / a;
b = 1 / b;
c = 1 / c;
}
}
}