Silverlight Geometry Graphics Game

Source: Internet
Author: User
Tags bool new features silverlight

Win7 installed a IE10, although there are many attractive new features, but in the debugging SL project, but found that its support for SL has a lot of problems, it seems that the elder brother must keep up with the trend of the times. This section should be the seal of the series, which day is free to implement a HTML5 version of it, but this SL code I will inadvertently to maintain, such as bug fixes, ease of use, and so do not need to constantly improve.

In the front we have realized the basic drawing function, such as point, line, circle and so on, these are all the functions of the ruler gauge drawing. But to achieve a fast and convenient drawing, only by this three piece is very inefficient, so we need to provide more complex some of the drawing skills, such as polygons, parallel, symmetrical points and so on, we call Composite graphics. The main task of this section is to provide a painting exercise for each composite graphic, the user completes the exercises after the corresponding drawing skills, and can use the new skills to solve new problems, not only rely on Dot line round three piece.

First we'll sort out which composite graphs are necessary, and prioritize them, for example, the midpoint is the intersection of the perpendicular bisector and the line, so after perpendicular bisector:

    Public enum Behaviororder   
    {   
        perpendicular bisector = 5,   
        midpoint = 6,   
        symmetric point = 7,   
        circumcircle = 8,   
        Parallel lines = 9,   
        vertical line =10,   
        angular split line = 11 ,   
        none=100,   
}

Then provide an interface definition for the exercise:

Public interface iexcercises   
    {   
        behaviororder behaviororder {get;} Skill   
        string Content {get;} Topic content (XML)   
        bool Validate (coordinatebase shape);//Validation policy   
        iexcercises Next {get;} Next Exercise   
    }

This interface is easy to understand, but it is not so easy to implement, the difficulty is to verify the strategy is difficult to determine, because there are many methods of drawing, we can not traverse all the methods, and can not be judged by simple coordinates, because this is likely to encounter accidental circumstances, such as the point of the user's painting exactly where. So, what should we do? In my practice, the main validation of the simplest general drawing ideas, and then by looking for dependencies to determine whether the map is correct, such as the perpendicular bisector line AB, the simplest way to draw is this:

1. A round a with the radius of AB (or BA) as the center of a.

2. A round B with a radius of AB (or BA) and B as the center.

3. Make the intersection of two circles C, D, the connection CD,CD is the request.

Then, the validation strategy is to verify its relationship with the segment CD based on a, b two points, and, if so, by verifying that the code is as follows:

public static bool Validate (Pointshape A, Pointshape B, LineShape line)   
        {   
            var CS = A.CS;   

            var Circlea = CS. Findcircle (A, A, B, false, false)?? Cs. Findcircle (A, B, A, false, 

false);   
            var Circleb = CS. Findcircle (b, A, B, false, false)?? Cs. Findcircle (b, B, A, False, 

false);   
            if (Circlea = null | | circleb = NULL) return false;   
            if (Circlea.parents[0]!= A) return false;   
            if (Circleb.parents[0]!= B) return false;   

            If line. P1. Dependentonall (False, Circlea, Circleb) && line   
                . P2. Dependentonall (False, Circlea, Circleb)) return   
                true;   

            return false;   
        }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.