Grids.MultiGrid.Intersects((UnityEngine.Vector2 start, UnityEngine.Vector2 end), (UnityEngine.Vector2 start, UnityEngine.Vector2 end), ref UnityEngine.Vector2)

Here are the examples of the csharp api Grids.MultiGrid.Intersects((UnityEngine.Vector2 start, UnityEngine.Vector2 end), (UnityEngine.Vector2 start, UnityEngine.Vector2 end), ref UnityEngine.Vector2) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 View Source File : MultiGrid.cs
License : MIT License
Project Creator : IxxyXR

public List<Rhomb> generateRhombs(int div, int dim, float offset, bool random=false)
        {
            var rhombs = new List<Rhomb>();
            var angles = new List<float>();

            int halfLines = div;
            int totalLines = (halfLines * 2) + 1;

            float randomAngle = 0;
            
            // Setup our imaginary lines...
            int dimensions = dim;
            if (random)
            {
                float angle = 0;
                while (angle < Mathf.PI)
                {
                    angle += Random.Range(.00001f, Mathf.PI/(div/2f));
                    angles.Add(angle);
                }
            }
            else
            {
                for (int i = 0; i < dimensions; i++)
                {
                    var angle = 2 * (Mathf.PI / dim) * i;
                    angles.Add(angle);
                }
            }


            for (int i = 0; i < angles.Count; i++)
            {
                float angle1 = angles[i];
                Vector2 p1 = new Vector2(totalLines * Mathf.Cos(angle1), -totalLines * Mathf.Sin(angle1));
                Vector2 p2 = -p1;

                for (int parallel1 = 0; parallel1 < totalLines; parallel1++)
                {
                    int index1 = halfLines - parallel1;

                    Vector2 offset1 = new Vector2((index1 + offset) * Mathf.Sin(angle1), (index1 + offset) * Mathf.Cos(angle1));
                    var l1 = (p1 + offset1, p2 + offset1);

                    for (int k = i + 1; k < angles.Count; k++)
                    {
                        float angle2 = angles[k];
                        var p3 = new Vector2(totalLines * Mathf.Cos(angle2), -totalLines * Mathf.Sin(angle2));
                        Vector2 p4 = -p3;
                        
                        for (int parallel2 = 0; parallel2 < totalLines; parallel2++)
                        {
                            int index2 = halfLines - parallel2;

                            var offset2 = new Vector2((index2 + offset) * Mathf.Sin(angle2), (index2 + offset) * Mathf.Cos(angle2));
                            var l2 = (p3 + offset2, p4 + offset2);
                            var intersect = new Vector2();

                            bool intersection = Intersects(l1, l2, ref intersect);
                            if (intersection)
                            {
                                List<int> indices = getIndicesFromPoint(intersect, angles, offset);
                                var shape = new List<Vector2>();
                                indices[i] = index1 + 1;
                                indices[k] = index2 + 1;
                                shape.Add(getVertex(indices, angles));
                                indices[i] = index1;
                                indices[k] = index2 + 1;
                                shape.Add(getVertex(indices, angles));
                                indices[i] = index1;
                                indices[k] = index2;
                                shape.Add(getVertex(indices, angles));
                                indices[i] = index1 + 1;
                                indices[k] = index2;
                                shape.Add(getVertex(indices, angles));
                                indices[i] = index1 + 1;
                                indices[k] = index2 + 1;
                                shape.Add(getVertex(indices, angles));

                                var rhomb = new Rhomb
                                {
                                    shape = shape,
                                    parallel1 = index1,
                                    parallel2 = index2,
                                    line1 = i,
                                    line2 = k,
                                };
                                rhombs.Add(rhomb);
                            }
                        }
                    }
                }
            }

            return rhombs;
        }