コード例 #1
0
ファイル: Triangle.cs プロジェクト: Olsyx/Hedra-Library
        public Triangle(Vector2 a, float ab, float ac, float alpha)
        {
            // https://www.mathsisfun.com/algebra/trig-solving-sas-triangles.html
            Vertices = new Vector2[3];
            Angles   = new float[3];

            Vertices[0] = a;
            Angles[0]   = alpha;

            float radAlpha = alpha * Mathf.Rad2Deg;
            float bc       = Mathf.Sqrt(Mathf.Pow(ac, 2) + Mathf.Pow(ab, 2) - 2 * ab * ac * Mathf.Cos(radAlpha));

            Angles[1] = Mathf.Asin((Mathf.Sin(radAlpha) * ac) / bc) * Mathf.Deg2Rad;
            Angles[2] = 180 - Angles[1] - Angles[0];

            Vertices[2] = Vertices[0] + Vector2.right * ac;
            Vertices[1] = Hedra.Rotate(Vertices[0], Vertices[2], Angles[0]).normalized *ab;

            CalculateCenter();

            CreateEdges();
            CreateNormals();
            StoreHeights();
            CalculateArea();
            rotation = 0;
        }
コード例 #2
0
 protected override void CreateVertices()
 {
     Vertices = Hedra.Circle(Center, Radius, vertexCount).ToArray();
     for (int i = 0; i < Vertices.Length; i++)
     {
         Vertices[i] = Hedra.Rotate(Center, Vertices[i], rotation);
     }
     SortVertices();
 }
コード例 #3
0
ファイル: Triangle.cs プロジェクト: Olsyx/Hedra-Library
        public Triangle(Vector2 position, float radius)
        {
            Vector2 a = position + Vector2.up * radius;
            Vector2 b = Hedra.Rotate(position, a, 120f);
            Vector2 c = Hedra.Rotate(position, a, -120f);

            Vertices = new Vector2[] { a, b, c };

            rotation = 0;
            Init();
        }
コード例 #4
0
ファイル: Rectangle.cs プロジェクト: Olsyx/Hedra-Library
        protected override void CreateVertices()
        {
            Vector2 halfSize = size / 2f;

            Vertices    = new Vector2[4];
            Vertices[0] = Hedra.Rotate(Center, new Vector2(Center.x - halfSize.x, Center.y + halfSize.y), Rotation);
            Vertices[1] = Hedra.Rotate(Center, new Vector2(Center.x + halfSize.x, Center.y + halfSize.y), Rotation);
            Vertices[2] = Hedra.Rotate(Center, new Vector2(Center.x + halfSize.x, Center.y - halfSize.y), Rotation);
            Vertices[3] = Hedra.Rotate(Center, new Vector2(Center.x - halfSize.x, Center.y - halfSize.y), Rotation);
            SortVertices();
        }
コード例 #5
0
ファイル: Segment2D.cs プロジェクト: Olsyx/Hedra-Library
        public virtual void DrawVector(float angle = 35, float size = 0.2f, bool oppositeDirection = false)
        {
            Gizmos.DrawLine(PointA, PointB);

            Vector2 origin    = oppositeDirection ? PointA : PointB;
            Vector2 vector    = oppositeDirection ? Vector.normalized : -Vector.normalized;
            Vector2 flapPoint = origin + vector * size;

            Vector2 flapA = Hedra.Rotate(origin, flapPoint, angle);
            Vector2 flapB = Hedra.Rotate(origin, flapPoint, -angle);

            Gizmos.DrawLine(origin, flapA);
            Gizmos.DrawLine(origin, flapB);
        }
コード例 #6
0
        public virtual void Rotate(float degrees)
        {
            rotation += degrees;

            for (int i = 0; i < Vertices.Length; i++)
            {
                Vertices[i] = Hedra.Rotate(Center, Vertices[i], degrees);
            }

            for (int i = 0; i < Edges.Length; i++)
            {
                Edges[i].Rotate(Center, degrees);
            }

            for (int i = 0; i < Normals.Length; i++)
            {
                Normals[i].Rotate(Center, degrees);
            }
        }
コード例 #7
0
ファイル: Line2D.cs プロジェクト: Olsyx/Hedra-Library
 public virtual void Rotate(Vector2 pivotPoint, float degrees) {
     PointA = Hedra.Rotate(pivotPoint, PointA, degrees);
     PointB = Hedra.Rotate(pivotPoint, PointB, degrees);
     Init();
 }