Silverlight mathematical engine (18)-geometric drawing game

Source: Internet
Author: User

I installed ie10 on Windows 7. Although there are many attractive new features, I found many problems with SL support when debugging the SL project, it seems that brother will keep up with the trend of the times. This section should be an article in this series. If you have time to implement an HTML5 version, I will maintain this SL code, for example, bug fixes and Usability Improvements do not need to be constantly improved.

Previously, we have implemented basic drawing functions, such as points, lines, and circles. These are all functions of ing. However, to achieve quick and convenient plotting, It is very inefficient to rely solely on the three major components. Therefore, we need to provide more complex drawing skills, such as polygon, parallel lines, and symmetric points, this is called composite graphics. The main work of this section is to provide a drawing exercise question for each composite graph. After completing the exercise question, the user can get the corresponding drawing skills and use the new skills to solve the new questions, you don't have to rely solely on the dot and wire circles.

First, we need to sort the composite images according to their priorities. For example, the midpoint is the intersection of the center vertical line and the line, so it is placed after the center vertical line:

Public Enum behaviororder {vertical line = 5, midpoint = 6, symmetric point = 7, Outer Circle = 8, parallel line = 9, vertical line = 10, angle bisector = 11, none = 100 ,}

Then provide an interface definition for exercise questions:

Public interface iexcercises {behaviororder {Get ;}// skill string content {Get ;}// question content (XML) bool validate (coordinatebase shape ); // verification policy iexcercises next {Get;} // next exercise}

This interface is easy to understand, but not so easy to implement. The difficulty is that the verification policy is hard to determine, because there are many plotting methods, and we cannot traverse all the methods, it cannot be determined by simple coordinate calculation, because it may encounter occasional situations, such as the location where the user draws the point. So, what should we do? In my exercises, I mainly verified the simplest and most common construction ideas, and then searched for dependencies to determine whether the images were correct, such as the center vertical line of line AB, the simplest plotting method is as follows:

1. Take AB (or BA) as the radius, and a as the center of the circle.

2. Take AB (or BA) as the radius, and B as the center of the circle B.

3. Make the intersection of the two circles C and D, connect to the CD, and the CD is what you want.

Then, the verification policy verifies the relationship between A and B and the line segment CD based on the two points. If yes, the verification 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;        }

It can be found that I have written this method as static for reuse. For example, the simplest way to draw a midpoint is to draw a vertical line first and then take the intersection point directly. Therefore, we only need to use the above verification method to find a vertical line and then verify the intersection. For example, the verification method of the midpoint is as follows:

        public static bool Validate(PointShape A, PointShape B, IntersectionPointOfLines midPoint)        {            var cs = A.CS;            var AB = cs.FindShapes<LineShape>(false, A, B).FirstOrDefault();            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;            var ps = cs.FindShapes<IntersectionPointOfCircles>(false, circleA, circleB);            if (ps.Count >= 2)            {                var CD = cs.FindShapes<LineShape>(false, ps[0], ps[1]).FirstOrDefault();                if (CD != null && midPoint.DependentOnAll(false, AB, CD))                    return true;            }            return false;        }

OK. When will the verification policy be verified? Of course, there are also many methods, such as traversing each graph to verify the efficiency. After all, we can minimize the scope of the object to be verified, passing through behavior is a good solution. The implementation code is as follows:

Public abstract class behaviorbase: ibehavior {//...... Public static iexcercises excercise; Public void finished (coordinatebase shape) {If (excercise! = NULL) {If (excercise. validate (SHAPE) {behaviors. where (B => B. order = excercise. behaviororder ). first (). host. visibility = visibility. visible; excercise = excercise. next; If (excercise! = NULL) {MessageBox. Show ("Congratulations! "); Shapeserializer. parse (excercise. Content, CS);} else {MessageBox. Show (" it's over! ");}}}}}

[Source code and demo address]

Http://www.diyuexi.com/webpages/query/ShareRes.aspx

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.