Chapter 3 Introduction to Triangle Learning application (1) (as3.0)

Source: Internet
Author: User
Tags acos asin

Starting from this chapter, we will learn about triangle learning and apply it to animation technology in chapter 5.
It will be exposed during the graphic technique. If you already know about triangle learning or want to learn about animation, you can
Skip this part and come back to study when you encounter problems that you don't understand in the future. 90% of triangle learning we use needs
Math. Sin and math. Cos are required. When I wrote the first version of this book, I once said that apart from studying in middle school
I have never accepted formal mathematical training because of the algebra and ry that I have used (and most of the time cannot be remembered ).
Training: The content in this chapter was originally from various books, websites or other network resources.
It is not difficult to know. Since I can learn, you can certainly. Now I have completed my college algebra and calculus.
This course also provides a more comprehensive and systematic understanding of triangle learning. It is a great honor to say that this chapter has excellent content,
Because I have a deeper understanding of this subject, I can explain it more clearly in many places.
What is trigonometry)
   Triangle learning is a discipline that studies the relationship between triangles and their sides and corners. When we observe a triangle, we find that it has
Three edges and three edges (hence called triangles), and there are some special relationships between these edges and edges. For example,
If you increase any angle, the edges corresponding to the angle will increase (assuming the length of the other two edges remains unchanged) at the same time,
                                                                          
,
The other two corners will become smaller. In fact, after calculating how much they have changed, a ratio can be obtained. In
In a triangle, if one of the angles is 90 degrees, it is called a right triangle and is marked at the angle of the angle.
A square (vertical) is only used in a right triangle. Learning the relationship between Cartesian triangles is more than derivation.
The basic formula is much simpler, which makes the right triangle a very useful structure.
Most of them are Cartesian triangles.
Angle)
   Angle is the most important research object of triangle science,Let's solve this problem first. An angle is a graph composed of two intersecting lines.
Or the space between two intersecting lines. The space is large and the angle is larger. In fact, the two intersecting lines are shaped
See Figure 3-1:

Figure 3-1 two lines form four corners
Radian and degress)
   Radians and angles are two special mechanisms in angle measurement. We are probably most familiar with or even close the angle system.
You can draw an angle of 45 degrees or 90 degrees on your eyes. The circle's 360-degree system has become a culture.

Turning refers to "turning in the opposite direction". This is not the turning direction, but the opposite view. Me
The point of view discussed in this article is radians for computers. Therefore, whether you like it or not, you must make a difference in radians.
Learn more.
   1 radian is about 57.2958 degrees. You may ask, "Is this logical ?" It does have its logic. A circle,
360 degrees, and the calculated radian is 6.2832. Still meaningless? Okay. I want to see if Pi (π) is equal
3.1416, and a circle (6.2832 radian) is equal to 2 pi. We know that 360 degrees is equivalent to 2 pi, and 180 degrees is equivalent
For Pi, 90 degrees is equivalent to PI/2, and so on. Figure 3-2 shows some commonly used radians.

Figure 3-2 radian and Angle
    From now on, we will begin to use radians, And we will encounter many situations in the future.
    The rotation attribute of video editing and sprite films must be angular, and attributes are frequently used.
. For example, if a car needs to rotate in the direction of motion, if the triangle is used to calculate the direction of motion, the obtained
Angle is expressed in radians, while angle is used for automobile rotation. Conversely, if you want to specify an object
The rotation angle is obtained, which is expressed by angle.
It must be converted to radians.
Angle, also applied to the filter, if you use the projection filter (drop shadow filter), to cast an object 45 degrees
You need to specify the angle rather than the radian, whether in Flash IED or using
All codes are the same.
    Why are there two completely different systems in a programming system? Maybe this is the dual nature of flash. Party
This is the designer's tool. It has all the drawing and deformation tools in Flash IDE and can draw beautiful
. If you say to a designer that you have rotated the logo text to a radian, you will surely be blinded. Another
On the one hand, Flash is also a development tool. It is more like a programming language, and you can use radians to compile it.
In short, whether you like them or not, you also need to master the conversion between angle and radians. To
The formula is as follows:
Radian (radians) = angle (degrees) * Math. PI/180
Angle (degrees) = radians (radians) * 180/Math. Pi
    There are many formulas in the course of learning this book. No matter where the formula needs to be remembered, I will refer
I hope you can remember it. Here is the first formula. You can find these formulas every time you need them,
But there is no ready-made code,Because these codes need to be typed in by hand. I write these public accounts using ActionScript.
For example, math. Pi is better than Pi or other characters, because it is consistent with the entered code.
    180 degrees equals 3.14... Radians. In other words, the half circle is pi radians, the whole circle is 2 pi radians, and
The radians are about 57.29... Degree.

Flash Coordinate System
   When discussing the angle, we should mention the flash coordinate system. If we are used to the mathematical coordinate system
The coordinate system may be a bit unaccustomed, because everything is reversed here. In the standard coordinate system
X indicates the horizontal axis, y indicates the vertical axis, and Flash is the same. When x = 0, y = 0, the coordinates (0, 0) are usually displayed in
Center position. If X is positive, it is on the right. If X is negative, it is on the left. If y is positive, it is on the top. If y is negative, it is on the bottom,
3-3.


Figure 3-3 standard Coordinate System
   However, Flash is based on the video screen coordinate system. Is the upper left corner, 3-4. The X value is constant from left to right.
Increase, but y axis is opposite, positive value downward, negative value upward. This system has its historical roots and creates a graph with screen scan.
The principle is as follows: from left to right, from top to bottom.

Figure 3-4 flash Coordinate System
   We can imagine a normal coordinate system, just to turn the Y axis upside down and migrate the center of the screen to the screen
. The following is an example. In a general coordinate system, the angle is calculated counterclockwise and starts with 0 degrees.
Draw a line to the X axis, as shown in 3-5.

Figure 3-5 normal angle
It is reversed in flash, as shown in 3-6. Clockwise rotation angle is positive. It is a negative angle in a counter-clockwise manner.

Figure 3-6 flash Angle
Triangle edge
   There is not much to say about the side of a triangle, but they all have their own terms. Taking a right triangle as an example,
As shown in 3-7, each edge has its own name. The two edges connected to the 90-degree angle are called the legs and the opposite edges.
It is called a oblique edge, which is always the longest side.

Figure 3-7 Right Triangle
    When talking about the opposite side, we say it is an edge that is not connected to the angle. When talking about the adjacent edge, it is the side connected to the corner. In very
In many examples, they all deal with the other two corners that are not 90 degrees. The most interesting thing about a triangle is the relationship between the angle and the edge,
These links are very useful for animation production. Let's take a look at them.
Trigonometric function
    ActionScript has a set of trigonometric functions used to calculate different triangular relationships: sine, cosine, tangent, and arc.
Returns the string, returns the arc cosine, and returns the arc tangent. Next we will start to define and use these functions, and then introduce their practical application.
Sine (SINE)
    The following is the first part of triangle learning. The sine value of an angle is equal to the aspect-to-oblique ratio of the angle.
In ActionScript, the math. Sin (angle) function is used for representation. As shown in 3-8, it is a sine of a 30 degree angle.
                                                  
Figure
The side length is 1, the oblique side is 2, the ratio of the two sides is 1 to 2, or 1/2 or 0.5, so we can say 30
The sine value of the degrees angle is 0.5, which is tested in flash as follows:
Trace (math. Sin (30 ));

Figure 3-the sine of the 8-angle is the opposite side/oblique side.
   The output result is-0.988031624092862. Why? Can you find the cause? This is because we forget
Converts the result to radians. I dare say that you will always make this mistake in the future (I am the same), so be careful.
The following statements are correct:
Trace (math. Sin (30 * Math. PI/180 ));
Successful! 0.5 output
   You may get 0.4999 more... This is not a program error, but because binary computers are often floating
Vertices represent numeric values. But this value is very close, so we think it is equal to 0.5.
You can imagine a triangle as 30 degrees, and the two sides are 1 and 2 respectively, and then move it to the normal coordinate system,
Do not forget that the Y axis of the flash coordinate system is clockwise. Therefore, the opposite side and angle are the opposite.

Therefore, the ratio is changed to-1/2, which is called the sine value of the-30 degree angle. At the same time, change the expression:
Trace (math. Sin (-30 * Math. PI/180 ));
   Okay, won't it be painful? Let's look at a trigonometric function: cosine.
Cosine (Cosine)
   In flash, you can use math. Cos (angle) to calculate the cosine. the cosine is defined as the adjacent edge and oblique angle.
Edge ratio.

Arccosine)
   Similar to tangent, arcsin and arccosine are rarely used in general Flash animation. However, we still need to learn
Their usage is actually the inverse functions of the sine and Cosine functions. In other words, enter a proportional value,
Returns an angle value (in radians ).
   In the ActionScript function, remember math. asin (ratio) and math. ACOs (ratio ). Next let's test
Try it. We already know that the sine value of the 30 degree angle is 0.5, so the arc sine value of 0.5 should be 30 degrees. Let's test it:
Trace (math. asin (0.5) * 180/Math. Pi );
Don't forget to convert the result to an angle system to get an angle of 30 degrees, instead of a radian of 0.523.
We know that the cosine of the 30 degree angle is about 0.865. We will test it in the same way:
Trace (math. ACOs (0.865) * 180/Math. Pi );
   The result 30.1172947473221 is displayed. If the cosine value of 30 degrees is entered more accurately, the result is obtained.
It will also be more accurate. How about it?

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.