Exemple #1
0
    //Is a point intersecting with a circle?
    private void PointCircle()
    {
        MyVector2 testPoint = pointTrans.position.ToMyVector2();

        MyVector2 circlePointA = t1_p1_trans.position.ToMyVector2();
        MyVector2 circlePointB = t1_p2_trans.position.ToMyVector2();
        MyVector2 circlePointC = t1_p3_trans.position.ToMyVector2();

        //Is a point in a circle determines by three other points
        IntersectionCases intersectionCases = _Intersections.PointCircle(circlePointA, circlePointB, circlePointC, testPoint);

        //print(isPointInCircle);


        //Display the circle
        //if (intersectionCases == IntersectionCases.NoIntersection)
        //{
        //    Gizmos.color = Color.white;
        //}
        //if (intersectionCases == IntersectionCases.IsInside)
        //{
        //    Gizmos.color = Color.red;
        //}
        //if (intersectionCases == IntersectionCases.IsOnEdge)
        //{
        //    Gizmos.color = Color.blue;
        //}


        MyVector2 centerOfCicle = _Geometry.CalculateCircleCenter(circlePointA, circlePointB, circlePointC);

        float radius = MyVector2.Distance(centerOfCicle, circlePointA);

        //Gizmos.DrawWireSphere(centerOfCicle.ToVector3(), radius);

        ////Display the points
        //float pointRadius = 0.2f;

        //Gizmos.DrawWireSphere(pointTrans.position, pointRadius);

        //Gizmos.DrawWireSphere(t1_p1_trans.position, pointRadius);
        //Gizmos.DrawWireSphere(t1_p2_trans.position, pointRadius);
        //Gizmos.DrawWireSphere(t1_p3_trans.position, pointRadius);


        //With mesh
        //Big circle
        TestAlgorithmsHelpMethods.DisplayCircleMesh(centerOfCicle, radius, 60, Color.white);

        //Small circle
        Color circleColor = (intersectionCases == IntersectionCases.IsInside) ? Color.red : Color.white;

        TestAlgorithmsHelpMethods.DisplayCircleMesh(testPoint, 1f, 20, circleColor);
    }
    //Generate circle meshes for delaunay based in 3 points in a triangle, where d is the opposite vertex
    public void GenerateDelaunayCircleMeshes(MyVector2 a, MyVector2 b, MyVector2 c, MyVector2 d)
    {
        //Remove all old meshes
        ClearBlackMeshes();


        //Unnormalize the points
        a = HelpMethods.UnNormalize(a, normalizingBox, dMax);
        b = HelpMethods.UnNormalize(b, normalizingBox, dMax);
        c = HelpMethods.UnNormalize(c, normalizingBox, dMax);
        d = HelpMethods.UnNormalize(d, normalizingBox, dMax);


        //Generate the triangles

        //Big circle
        MyVector2 center = Geometry.CalculateCircleCenter(a, b, c);

        float radius = MyVector2.Distance(center, a);

        HashSet <Triangle2> allTriangles = GenerateMesh.CircleHollow(center, radius, 100, 0.1f);


        //Circles showing the 4 points
        float circleMeshRadius = 0.3f;

        HashSet <Triangle2> circle_a = GenerateMesh.Circle(a, circleMeshRadius, 10);
        HashSet <Triangle2> circle_b = GenerateMesh.Circle(b, circleMeshRadius, 10);
        HashSet <Triangle2> circle_c = GenerateMesh.Circle(c, circleMeshRadius, 10);
        HashSet <Triangle2> circle_d = GenerateMesh.Circle(d, circleMeshRadius, 10);

        //Similar to List's add range
        allTriangles.UnionWith(circle_a);
        allTriangles.UnionWith(circle_b);
        allTriangles.UnionWith(circle_c);
        allTriangles.UnionWith(circle_d);


        //Active edge is a-c
        HashSet <Triangle2> activeEdgeMesh = GenerateMesh.LineSegment(a, c, 0.2f);

        allTriangles.UnionWith(activeEdgeMesh);


        //Generate meshes
        foreach (Triangle2 t in allTriangles)
        {
            Mesh triangleMesh = Triangle2ToMesh(t, 0.1f);

            blackMeshes.Add(triangleMesh);
        }
    }
Exemple #3
0
        private List <MyVector2> ExtractOutline(Image <Gray, byte> imgs, List <MyVector2> topOutline)
        {
            double           lineDistTheshold = 5;
            List <MyVector2> ObjectOutline    = GetBoundaryPoints(edgeImage);
            List <MyVector2> Boundary2        = new List <MyVector2>();

            foreach (var p_obj in ObjectOutline)
            {
                bool IsColosed = false;
                foreach (var p_top in topOutline)
                {
                    if (MyVector2.Distance(p_obj, p_top) < lineDistTheshold)
                    {
                        IsColosed = true;
                    }
                }
                if (!IsColosed)
                {
                    Boundary2.Add(p_obj);
                }
            }
            return(Boundary2);
        }
Exemple #4
0
    //Generate circle meshes for delaunay based in 3 points in a triangle, where d is the opposite vertex
    public HashSet <Triangle2> GenerateDelaunayCircleTriangles(MyVector2 a, MyVector2 b, MyVector2 c, MyVector2 d)
    {
        //Unnormalize the points
        a = UnNormalize(a);
        b = UnNormalize(b);
        c = UnNormalize(c);
        d = UnNormalize(d);


        //Generate the triangles

        //Big circle
        MyVector2 center = _Geometry.CalculateCircleCenter(a, b, c);

        float radius = MyVector2.Distance(center, a);

        HashSet <Triangle2> allTriangles = _GenerateMesh.CircleHollow(center, radius, 100, 0.1f);


        //Circles showing the 4 points
        float circleMeshRadius = 0.3f;

        HashSet <Triangle2> circle_a = _GenerateMesh.Circle(a, circleMeshRadius, 10);
        HashSet <Triangle2> circle_b = _GenerateMesh.Circle(b, circleMeshRadius, 10);
        HashSet <Triangle2> circle_c = _GenerateMesh.Circle(c, circleMeshRadius, 10);
        HashSet <Triangle2> circle_d = _GenerateMesh.Circle(d, circleMeshRadius, 10);

        //Similar to List's add range
        allTriangles.UnionWith(circle_a);
        allTriangles.UnionWith(circle_b);
        allTriangles.UnionWith(circle_c);
        allTriangles.UnionWith(circle_d);


        return(allTriangles);
    }