Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
魔术师Dix
Unity几何库:木蝴蝶
提交
24773abb
Unity几何库:木蝴蝶
项目概览
魔术师Dix
/
Unity几何库:木蝴蝶
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Unity几何库:木蝴蝶
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
24773abb
编写于
11月 10, 2022
作者:
魔术师Dix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
平面与直线的交点计算;
上级
b2551d25
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
171 addition
and
4 deletion
+171
-4
Intersection/IntrLine3dPlane.cs
Intersection/IntrLine3dPlane.cs
+37
-3
Math/Line3d.cs
Math/Line3d.cs
+11
-1
Math/Plane3d.cs
Math/Plane3d.cs
+103
-0
Math/Plane3d.cs.meta
Math/Plane3d.cs.meta
+11
-0
OMath.cs
OMath.cs
+9
-0
未找到文件。
Intersection/IntrLine3dPlane.cs
浏览文件 @
24773abb
...
...
@@ -7,7 +7,6 @@
*版本: 1.0
*/
using
Unity.Mathematics
;
namespace
Oroxylum
...
...
@@ -15,9 +14,44 @@ namespace Oroxylum
/// <summary>
/// 计算结果:3d直线与线段
/// </summary>
public
struct
IntrLine3dPlane
public
struct
IntrLine3dPlane
{
public
E_IntersectionResult
Result
;
public
E_IntersectionType
Type
;
public
float3
CastPoint
;
public
IntrLine3dPlane
(
Line3d
line
,
Plane3d
plane
)
{
Result
=
E_IntersectionResult
.
NotComputed
;
float
d1
=
math
.
dot
(
plane
.
PlanePoint
-
line
.
Origin
,
plane
.
Normal
);
float
d2
=
math
.
dot
(
line
.
Direction
,
plane
.
Normal
);
if
(
d2
==
0
)
{
float
distance
=
plane
.
GetDistanceToPoint
(
line
.
Origin
);
if
(
distance
<=
OMath
.
ZeroTolerance
)
{
//直线就在平面上;
Type
=
E_IntersectionType
.
Line
;
Result
=
E_IntersectionResult
.
NotComputed
;
CastPoint
=
line
.
Origin
;
}
else
{
//此时直线与平面平行;
Type
=
E_IntersectionType
.
Empty
;
Result
=
E_IntersectionResult
.
NoIntersection
;
CastPoint
=
float
.
MaxValue
;
}
return
;
}
Type
=
E_IntersectionType
.
Point
;
Result
=
E_IntersectionResult
.
Intersects
;
CastPoint
=
(
d1
/
d2
*
line
.
Direction
)
+
line
.
Origin
;
}
}
}
}
\ No newline at end of file
Math/Line3d.cs
浏览文件 @
24773abb
...
...
@@ -8,6 +8,7 @@
*/
using
Unity.Mathematics
;
using
UnityEngine
;
namespace
Oroxylum
{
...
...
@@ -17,12 +18,21 @@ namespace Oroxylum
public
struct
Line3d
{
public
float3
Origin
;
/// <summary>
/// 直线方向,已经 normalize
/// </summary>
public
float3
Direction
;
public
Line3d
(
float3
origin
,
float3
direction
)
{
this
.
Origin
=
origin
;
this
.
Direction
=
direction
;
this
.
Direction
=
math
.
normalize
(
direction
);
}
public
Line3d
(
Ray
ray
)
{
this
.
Origin
=
ray
.
origin
;
this
.
Direction
=
ray
.
direction
;
}
public
static
Line3d
FromPoints
(
float3
p0
,
float3
p1
)
...
...
Math/Plane3d.cs
0 → 100644
浏览文件 @
24773abb
/*
*Copyright(C) 2020 by Cyf All rights reserved.
*Unity版本:2021.3.11f1c2
*作者:程一峰
*创建日期: 2022-11-10
*模块说明:木蝴蝶数学库:数据格式
*版本: 1.0
*/
using
Unity.Mathematics
;
using
UnityEngine
;
namespace
Oroxylum
{
/// <summary>
/// 平面,与 UnityEngine.Plane 等价;
/// 不用Unity的Plane是因为其是基于 Vector 构建的;
/// 而 Plane3d 是基于 float3 构建
/// </summary>
public
struct
Plane3d
{
/// <summary>
/// 平面法线方向,已经 normalize
/// </summary>
public
float3
Normal
;
public
float
Distance
;
/// <summary>
/// 平面上的一点;
/// </summary>
public
float3
PlanePoint
=>
Normal
*
-
Distance
;
/// <summary>
/// 构造平面
/// </summary>
/// <param name="normal">法线</param>
/// <param name="distance">平面到原点的距离</param>
public
Plane3d
(
float3
normal
,
float
distance
)
{
Normal
=
math
.
normalize
(
normal
);
Distance
=
distance
;
}
/// <summary>
/// 构造平面
/// </summary>
/// <param name="normal">法线</param>
/// <param name="point">平面上一点</param>
public
Plane3d
(
float3
normal
,
float3
point
)
{
Normal
=
math
.
normalize
(
normal
);
Distance
=
-
math
.
dot
(
Normal
,
point
);
}
// N = Cross(P1-P0,P2-P0)/Length(Cross(P1-P0,P2-P0)), c = Dot(N,P0) where
// P0, P1, P2 are points on the plane.
/// <summary>
/// 根据平面上的3个点进行构建;
/// </summary>
public
Plane3d
(
float3
a
,
float3
b
,
float3
c
)
{
Normal
=
math
.
normalize
(
math
.
cross
(
b
-
a
,
c
-
a
));
Distance
=
-
math
.
dot
(
Normal
,
a
);
}
public
Plane3d
(
Plane
p
)
{
Normal
=
p
.
normal
;
Distance
=
p
.
distance
;
}
// Compute d = Dot(N,P)-c where N is the plane normal and c is the plane
// constant. This is a signed distance. The sign of the return value is
// positive if the point is on the positive side of the plane, negative if
// the point is on the negative side, and zero if the point is on the
// plane.
public
float
GetDistanceToPoint
(
float3
p
)
{
return
Normal
.
Dot
(
p
)
-
Distance
;
}
// The "positive side" of the plane is the half space to which the plane
// normal points. The "negative side" is the other half space. The
// function returns +1 when P is on the positive side, -1 when P is on the
// the negative side, or 0 when P is on the plane.
public
int
WhichSide
(
float3
p
)
{
double
distance
=
GetDistanceToPoint
(
p
);
if
(
distance
<
0
)
return
-
1
;
else
if
(
distance
>
0
)
return
+
1
;
else
return
0
;
}
public
bool
SameSide
(
float3
inPt0
,
float3
inPt1
)
{
float
distanceToPoint
=
GetDistanceToPoint
(
inPt0
);
float
distanceToPoint2
=
GetDistanceToPoint
(
inPt1
);
return
(
distanceToPoint
>
0f
&&
distanceToPoint2
>
0f
)
||
(
distanceToPoint
<=
0f
&&
distanceToPoint2
<=
0f
);
}
}
}
Math/Plane3d.cs.meta
0 → 100644
浏览文件 @
24773abb
fileFormatVersion: 2
guid: b1abfdd23e097334abac5f2a46dd672e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
OMath.cs
浏览文件 @
24773abb
...
...
@@ -152,6 +152,15 @@ namespace Oroxylum
public
static
float3
Cross
(
this
float2
a
,
float2
b
)
{
return
(
a
.
x
*
b
.
y
)
-
(
a
.
y
*
b
.
x
);
}
public
static
float3
UnitCross
(
this
float3
v1
,
float3
v2
)
{
float3
n
=
new
float3
(
(
v1
.
y
*
v2
.
z
)
-
(
v1
.
z
*
v2
.
y
),
(
v1
.
z
*
v2
.
x
)
-
(
v1
.
x
*
v2
.
z
),
(
v1
.
x
*
v2
.
y
)
-
(
v1
.
y
*
v2
.
x
));
return
math
.
normalize
(
n
);
}
public
static
float
LengthSquared
(
this
float2
a
)
{
return
math
.
lengthsq
(
a
);
}
public
static
float
LengthSquared
(
this
float3
a
)
{
return
math
.
lengthsq
(
a
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录