Class LineUtil
直線に関する便利関数
Inheritance
Inherited Members
Namespace: PLATEAU.Util.GeoGraph
Assembly: cs.temp.dll.dll
Syntax
public static class LineUtil
Methods
CheckDistance(LineUtil.Line, Single, in Ray)
線分lineとrayの距離を測る ただし、radius以上離れていたら無効値を返す
Declaration
public static float CheckDistance(LineUtil.Line line, float radius, in Ray ray)
Parameters
Type | Name | Description |
---|---|---|
LineUtil.Line | line | |
System.Single | radius | |
Ray | ray |
Returns
Type | Description |
---|---|
System.Single |
CheckHit(LineUtil.Line, Single, in Ray, out Vector3, out Vector3)
線分lineとrayの衝突判定を行う radiusで判定に余裕を持たせる また、closestPointは衝突地点ではなく線分上の最も近い点なので注意
Declaration
public static float CheckHit(LineUtil.Line line, float radius, in Ray ray, out Vector3 closestPoint, out Vector3 closestPoint2)
Parameters
Type | Name | Description |
---|---|---|
LineUtil.Line | line | |
System.Single | radius | |
Ray | ray | |
Vector3 | closestPoint | |
Vector3 | closestPoint2 |
Returns
Type | Description |
---|---|
System.Single |
ClosestPoints(LineUtil.Line, LineUtil.Line, out Vector3, out Vector3)
交差しないline0とline1の最短距離を求める ただし、line0,line1は線分ではなく永遠に延びる直線として扱う 交差する場合は動作未定義
Declaration
public static void ClosestPoints(LineUtil.Line line0, LineUtil.Line line1, out Vector3 closestPoint1, out Vector3 closestPoint2)
Parameters
Type | Name | Description |
---|---|---|
LineUtil.Line | line0 | |
LineUtil.Line | line1 | |
Vector3 | closestPoint1 | |
Vector3 | closestPoint2 |
ContainsPoint(in LineUtil.Line, in Vector3)
line上にpointが存在するかどうかを判定する ただし pointはlineの延長線上にあることを前提とする
Declaration
public static bool ContainsPoint(in LineUtil.Line line, in Vector3 point)
Parameters
Type | Name | Description |
---|---|---|
LineUtil.Line | line | |
Vector3 | point |
Returns
Type | Description |
---|---|
System.Boolean |
DistanceBetweenLines(in LineUtil.Line, in LineUtil.Line, out Boolean)
2直線の距離を求める
Declaration
public static float DistanceBetweenLines(in LineUtil.Line line1, in LineUtil.Line line2, out bool isParallel)
Parameters
Type | Name | Description |
---|---|---|
LineUtil.Line | line1 | |
LineUtil.Line | line2 | |
System.Boolean | isParallel |
Returns
Type | Description |
---|---|
System.Single |
FindClosestPoint(LineUtil.Line, in Ray, out Vector3, out Vector3)
最近棒を求める 直線で計算するので注意
Declaration
public static float FindClosestPoint(LineUtil.Line line, in Ray ray, out Vector3 closestPoint, out Vector3 closestPoint2)
Parameters
Type | Name | Description |
---|---|---|
LineUtil.Line | line | |
Ray | ray | |
Vector3 | closestPoint | |
Vector3 | closestPoint2 |
Returns
Type | Description |
---|---|
System.Single |
GetLineSegmentLength(IEnumerable<Vector3>)
verticesで構成された線分の長さを求める
Declaration
public static float GetLineSegmentLength(IEnumerable<Vector3> vertices)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Vector3> | vertices |
Returns
Type | Description |
---|---|
System.Single |
GetLineSegmentLerpPoint(IReadOnlyList<Vector3>, Single, out Vector3)
verticesを頂点とした連続した線分に対して, 前半と後半の長さがp : (1-p)でとなるをmidPointに入れて返す. 戻り値は midPointを含む線分のインデックスがfloatで返る. 空頂点だと-1が返る
Declaration
public static float GetLineSegmentLerpPoint(IReadOnlyList<Vector3> vertices, float p, out Vector3 midPoint)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<Vector3> | vertices | |
System.Single | p | |
Vector3 | midPoint |
Returns
Type | Description |
---|---|
System.Single |
GetLineSegmentMidPoint(IReadOnlyList<Vector3>, out Vector3)
verticesで表される線分の中央地点を返す. 戻り値はvertices[i] ~ vertices[i+1]に中央地点があるときのi verticesが空の時は-1が返る
Declaration
public static float GetLineSegmentMidPoint(IReadOnlyList<Vector3> vertices, out Vector3 midPoint)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<Vector3> | vertices | |
Vector3 | midPoint |
Returns
Type | Description |
---|---|
System.Single |
GetNearestPoint(Ray2D, Vector2)
pからselfへの最も近い点を返す.
Declaration
public static Vector2 GetNearestPoint(this Ray2D self, Vector2 p)
Parameters
Type | Name | Description |
---|---|---|
Ray2D | self | |
Vector2 | p |
Returns
Type | Description |
---|---|
Vector2 |
GetNearestPoint(Ray2D, Vector2, out Single)
pからselfへの最も近い点を返す. tはreturn = self.origin + self.direction * tとなるt
Declaration
public static Vector2 GetNearestPoint(this Ray2D self, Vector2 p, out float t)
Parameters
Type | Name | Description |
---|---|---|
Ray2D | self | |
Vector2 | p | |
System.Single | t |
Returns
Type | Description |
---|---|
Vector2 |
GetNearestPointWithRay(Vector3, Vector3, Vector3)
p0,p1を通る直線に対して,aから最も近い直線状のポイントを返す
Declaration
public static Vector3 GetNearestPointWithRay(Vector3 p0, Vector3 p1, Vector3 a)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | p0 | |
Vector3 | p1 | |
Vector3 | a |
Returns
Type | Description |
---|---|
Vector3 |
HalfLineSegmentIntersection(Ray2D, Vector2, Vector2, out Vector2, out Single, out Single)
半直線halfLineと線分(p1, p2)の交点を返す. 交わらない場合はfalseが返る
Declaration
public static bool HalfLineSegmentIntersection(Ray2D halfLine, Vector2 p1, Vector2 p2, out Vector2 intersection, out float halfLineOffset, out float t2)
Parameters
Type | Name | Description |
---|---|---|
Ray2D | halfLine | |
Vector2 | p1 | 線分を構成する点1 |
Vector2 | p2 | 線分を構成する点2 |
Vector2 | intersection | 交点 |
System.Single | halfLineOffset | intersection = halfLine.origin + halfLine.direction * halfLineOffsetとなる値 |
System.Single | t2 | intersection = Vector2.Lerp(p1, p2, t2)となる値 |
Returns
Type | Description |
---|---|
System.Boolean |
Intersect(in LineUtil.Line, in LineUtil.Line, out Vector3)
交差するline0とline1の交点を求める 注意点としてline0,line1は線分ではなく永遠に延びる直線として扱う 交差しない場合は動作未定義
Declaration
public static bool Intersect(in LineUtil.Line line0, in LineUtil.Line line1, out Vector3 intersectionPoint)
Parameters
Type | Name | Description |
---|---|---|
LineUtil.Line | line0 | |
LineUtil.Line | line1 | |
Vector3 | intersectionPoint |
Returns
Type | Description |
---|---|
System.Boolean |
IsMouseDown()
Declaration
public static bool IsMouseDown()
Returns
Type | Description |
---|---|
System.Boolean |
IsPointOnLineSegment(LineUtil.Line, Vector3)
ライン上にポイントが存在するかどうかを判定する
Declaration
[Obsolete("動作未検証の関数")]
public static bool IsPointOnLineSegment(LineUtil.Line line, Vector3 p)
Parameters
Type | Name | Description |
---|---|---|
LineUtil.Line | line | |
Vector3 | p |
Returns
Type | Description |
---|---|
System.Boolean |
LineIntersection(Ray2D, Ray2D, out Vector2, out Single, out Single)
直線rayAと直線rayBの交点を求める
Declaration
public static bool LineIntersection(Ray2D rayA, Ray2D rayB, out Vector2 intersection, out float rayAOffset, out float rayBOffset)
Parameters
Type | Name | Description |
---|---|---|
Ray2D | rayA | |
Ray2D | rayB | |
Vector2 | intersection | |
System.Single | rayAOffset | intersection = rayA.origin + ray.direction * rayAOffsetとなる値 |
System.Single | rayBOffset | intersection = rayB.origin + ray.direction * rayBOffsetとなる値 |
Returns
Type | Description |
---|---|
System.Boolean |
LineIntersection(Vector2, Vector2, Vector2, Vector2, out Vector2, out Single, out Single)
a,bを通る直線,c,dを通る直線の交点を求める 平行な場合はfalse 交わる場合 intersectionに交点が入る
Declaration
public static bool LineIntersection(Vector2 a, Vector2 b, Vector2 c, Vector2 d, out Vector2 intersection, out float abT, out float cdT)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | a | 直線1の始点 |
Vector2 | b | 直線1の終点 |
Vector2 | c | 直線2の始点 |
Vector2 | d | 直線2の終点 |
Vector2 | intersection | 交点が入る |
System.Single | abT | intersection = Vector2.LerpUnclamped(a, b, abT)となるabTが入る |
System.Single | cdT | intersection = Vector2.LerpUnclamped(c, d, cdT)となるcdTが入る |
Returns
Type | Description |
---|---|
System.Boolean |
LineSegmentIntersection(Ray2D, Vector2, Vector2, out Vector2, out Single, out Single)
直線lineと線分(p1,p2)の交点を返す 交わらない場合はfalseが返る
Declaration
public static bool LineSegmentIntersection(Ray2D line, Vector2 p1, Vector2 p2, out Vector2 intersection, out float lineOffset, out float segmentT)
Parameters
Type | Name | Description |
---|---|---|
Ray2D | line | |
Vector2 | p1 | |
Vector2 | p2 | |
Vector2 | intersection | |
System.Single | lineOffset | intersection = line.origin + line.direction * lineOffsetとなる値 |
System.Single | segmentT | intersection = Vector2.LerpUnClamped(p1, p2, segmentT)となる値 |
Returns
Type | Description |
---|---|
System.Boolean |
SegmentIntersection(Vector2, Vector2, Vector2, Vector2, out Vector2, out Single, out Single)
線分h(s1St, s1En)と線分(s2St, s2En)の交点を返す. 交わらない場合はfalseが返る
Declaration
public static bool SegmentIntersection(Vector2 s1St, Vector2 s1En, Vector2 s2St, Vector2 s2En, out Vector2 intersection, out float t1, out float t2)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | s1St | 線分1を構成する点1 |
Vector2 | s1En | 線分1を構成する点2 |
Vector2 | s2St | 線分2を構成する点1 |
Vector2 | s2En | 線分2を構成する点2 |
Vector2 | intersection | |
System.Single | t1 | intersection = Vector2.Lerp(s1St, s1En, t1)となるt1が入る |
System.Single | t2 | intersection = Vector2.Lerp(s2St, s2En, t2)となるt2が入る |
Returns
Type | Description |
---|---|
System.Boolean |
SplitLineSegments(IReadOnlyList<Vector3>, Int32)
verticesで表される線分をsplitNumで等分する
Declaration
public static List<List<Vector3>> SplitLineSegments(IReadOnlyList<Vector3> vertices, int num)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<Vector3> | vertices | |
System.Int32 | num |
Returns
Type | Description |
---|---|
List<List<Vector3>> |