Tanoda
LocalSegment3.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using Leap.Unity.Infix;
11using System.Collections;
12using System.Collections.Generic;
13using UnityEngine;
14
15namespace Leap.Unity.Geometry {
16
17 public struct LocalSegment3 {
18
19 public Vector3 a, b;
20
21 public LocalSegment3(Vector3 a, Vector3 b) {
22 this.a = a;
23 this.b = b;
24 }
25
30 public float Parameterize(Vector3 pointOnSegment) {
31 if ((a - b).sqrMagnitude < float.Epsilon) return 0f;
32 return (pointOnSegment - a).magnitude / (b - a).magnitude;
33 }
34
35 public Vector3 Evaluate(float t) {
36 var ab = b - a;
37 return a + ab * t;
38 }
39
40 public LocalSegment3 Transform(Matrix4x4 m, bool fullMultiply = false) {
41 if (fullMultiply) {
42 return new LocalSegment3(m.MultiplyPoint(a), m.MultiplyPoint(b));
43 }
44 else {
45 return new LocalSegment3(m.MultiplyPoint3x4(a), m.MultiplyPoint3x4(b));
46 }
47 }
48
49 #region Collision
50
54 public float Intersect(Rect rect) {
55 return Collision.Intersect(this, rect);
56 }
57
58 #endregion
59
60 #region Runtime Gizmos
61
63 drawer.DrawLine(a, b);
64 }
65
66 #endregion
67
68 }
69
70}
void DrawLine(Vector3 a, Vector3 b)
Draws a gizmo line that connects the two positions.
LocalSegment3 Transform(Matrix4x4 m, bool fullMultiply=false)
float Parameterize(Vector3 pointOnSegment)
Given a point on the segment, parameterizes that point into a value such that a + (b - a)....
LocalSegment3(Vector3 a, Vector3 b)
void DrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
float Intersect(Rect rect)
Returns the squared distance between this line segment and the rect.