示例#1
0
        private MyVector3 GetLocalTangential(int p, List <MyVector3> boundary3, MyVector3 curDir)
        {
            // Get Nearnest Pointss
            List <NearPoint> nearPs = new List <NearPoint>();

            for (int i = 0; i < boundary3.Count; i++)
            {
                NearPoint p_i = new NearPoint();
                p_i.v     = boundary3[i];
                p_i.dist  = (boundary3[p] - p_i.v).Length();
                p_i.index = i;
                nearPs.Add(p_i);
            }

            // Fit Line with k nearest points
            int k = 100;
            List <NearPoint> kNearPs = (from a in nearPs orderby a.dist ascending select a).Take(k).ToList();
            List <MyVector3> kNearPv = new List <MyVector3>();

            foreach (var kNearP in kNearPs)
            {
                kNearPv.Add(kNearP.v);
            }
            var   fitline = new RansacLine3d(0.00005, 0.9);
            Line3 line3d  = fitline.Estimate(kNearPv);

            // Check Local Tangential Direction
            if (line3d.dir.Dot(curDir) < 0)
            {
                line3d.dir = -1 * line3d.dir;
            }
            return(line3d.dir.Normalize());
        }
示例#2
0
    public void Near()
    {
        List <Point> listPoints = GameObject.Find("Map").GetComponent <MapManager>()._listPoints;

        _pos = listPoints.FindIndex(x => x == this);

        _nearPoints.Clear();

        GetComponent <PolygonCollider2D>().enabled = false;

        for (int i = 0; i < (int)Dir.Max; ++i)
        {
            Dir dir = (Dir)i;

            NearPoint near = new NearPoint();
            near.dir  = dir;
            near.name = dir.ToString();

            RaycastHit2D hit = Physics2D.Raycast(Get_Pos(), _points[i].position - Get_Pos());

            if (null != hit.collider)
            {
                near.point = hit.collider.GetComponent <Point>();
            }

            _nearPoints.Add(near);
        }

        GetComponent <PolygonCollider2D>().enabled = true;
    }
示例#3
0
    public Point Get_NearPoint(Dir dir)
    {
        NearPoint near = _nearPoints.Find(x => x.dir == dir);

        if (null != near)
        {
            return(near.point);
        }
        return(null);
    }
示例#4
0
 private void SetCurrentDirection(NearPoint nearPoint = null)
 {
     _currentDirection  = nearPoint?.Direction ?? Direction.Stop;
     Global.Me.NextStep = nearPoint;
 }