提交 b2551d25 编写于 作者: 魔术师Dix's avatar 魔术师Dix

新增数据结构 line3d,并移除重复的数据结构plane(使用Unity自带的即可);

上级 55d15f97
......@@ -8,6 +8,8 @@
*/
using Unity.Mathematics;
namespace Oroxylum
{
/// <summary>
......@@ -16,6 +18,6 @@ namespace Oroxylum
public struct IntrLine3dPlane
{
}
}
......@@ -34,6 +34,12 @@ namespace Oroxylum
public double Project(float2 p) { return (p - Origin).Dot(Direction); }
public float2 ClosestPoint(float2 p)
{
float t = (p - Origin).Dot(Direction);
return Origin + t * Direction;
}
public double DistanceSquared(float2 p)
{
float t = (p - Origin).Dot(Direction);
......
/*
*Copyright(C) 2020 by Cyf All rights reserved.
*Unity版本:2021.3.11f1c2
*作者:程一峰
*创建日期: 2022-11-10
*模块说明:木蝴蝶数学库:数据格式
*版本: 1.0
*/
using Unity.Mathematics;
namespace Oroxylum
{
/// <summary>
/// 3d 直线
/// </summary>
public struct Line3d
{
public float3 Origin;
public float3 Direction;
public Line3d(float3 origin, float3 direction)
{
this.Origin = origin;
this.Direction = direction;
}
public static Line3d FromPoints(float3 p0, float3 p1)
{
return new Line3d(p0, math.normalize(p1 - p0));
}
public float Project(float3 p) { return (p - Origin).Dot(Direction); }
public float3 ClosestPoint(float3 p)
{
float t = (p - Origin).Dot(Direction);
return Origin + t * Direction;
}
public float DistanceSquared(float3 p)
{
float t = (p - Origin).Dot(Direction);
float3 proj = Origin + t * Direction;
return (proj - p).LengthSquared();
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 4ea5947ca82e2104da89c84439ced2f7
guid: 43c47208483b92d40b735849b69bfff2
MonoImporter:
externalObjects: {}
serializedVersion: 2
......
/*
*Copyright(C) 2020 by Cyf All rights reserved.
*Unity版本:2021.3.11f1c2
*作者:程一峰
*创建日期: 2022-11-10
*模块说明:木蝴蝶数学库:数据格式
*版本: 1.0
*/
namespace Oroxylum
{
/// <summary>
/// 平面
/// </summary>
public struct Plane
{
}
}
\ No newline at end of file
......@@ -154,6 +154,8 @@ namespace Oroxylum
public static float LengthSquared(this float2 a) { return math.lengthsq(a); }
public static float LengthSquared(this float3 a) { return math.lengthsq(a); }
public static float DotPerp(this float2 a, float2 b) { return (a.x * b.y) - (a.y * b.x); }
/// <summary>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册