# as3绘制抛物线

1、曲线开始的起点和结束的终点位置，可根据攻击方、被攻击方确定下来；

2、特效播放完毕后，需要知道它的结束时刻，以便回调函数里响应被攻击方的动作；

y1 = a * x1 * x1 + b * x1 + c;

y2 = a * x2 * x2 + b * x2 + c;

y3 = a * x3 * x3 + b * x3 + c;

b = ((y1 - y3) * (x1 * x1 - x2 * x2) - (y1 - y2) * (x1 * x1 - x3 * x3)) / ((x1 - x3) * (x1 * x1 - x2 * x2) - (x1 - x2) * (x1 * x1 - x3 * x3)); a = ((y1 - y2) - b * (x1 - x2)) / (x1 * x1 - x2 * x2); c = y1 - a * x1 * x1 - b * x1;

```1: package

2: {

3:     import flash.geom.Point;

4:     /**

5:      * ...

6:      * @author Meteoric

7:      */

8:     public class Parabola

9:     {

10:         private var startPt:Point;

11:         private var endPt:Point;

12:         private var vertexPt:Point;

13:

14:         private var a:Number;

15:         private var b:Number;

16:         private var c:Number;

17:

18:         public function Parabola(pt1:Point, pt2:Point)

19:         {

20:             startPt = pt1;

21:             endPt = pt2;

22:

23:             parse();

24:         }

25:

26:         public function parse(waveHeight:Number=140):void

27:         {

28:             vertexPt = new Point(startPt.x + (endPt.x - startPt.x) / 2, endPt.y - waveHeight);

29:

30:             var x1:Number = startPt.x;

31:             var x2:Number = endPt.x;

32:             var x3:Number = vertexPt.x;

33:

34:             var y1:Number = startPt.y;

35:             var y2:Number = endPt.y;

36:             var y3:Number = vertexPt.y;

37:

38:             b = ((y1 - y3) * (x1 * x1 - x2 * x2) - (y1 - y2) * (x1 * x1 - x3 * x3)) / ((x1 - x3) * (x1 * x1 - x2 * x2) - (x1 - x2) * (x1 * x1 - x3 * x3));

39:             a = ((y1 - y2) - b * (x1 - x2)) / (x1 * x1 - x2 * x2);

40:             c = y1 - a * x1 * x1 - b * x1;

41:

42:             trace(a, b, c);

43:         }

44:

45:         public function getY(posX:Number):Number

46:         {

47:             var posY:Number = a * posX * posX + b * posX + c;

48:

49:             return posY;

50:         }

51:

52:     }

53:

54: }```

412 篇文章24 人订阅

0 条评论

## 相关文章

952

### 浅扒Android动态设置字体大小

Android开发中,TextView类的控件应该说是很常用了。一般来说我们是通过android:textSize="20sp" 来设置字体大小，但是很多时候...

1443

1231

### （数据科学学习手札42）folium进阶内容介绍

在上一篇（数据科学学习手札41）中我们了解了folium的基础内容，实际上folium在地理信息可视化上的真正过人之处在于其绘制图像的高度可定制化上，本文就...

3034

1482

2906

2315

3827

27010

### android动画之interpolator和typeEvaluator用法详解

Interpolator （插值器） 我们在写动画的时候为了达到某种效果往往需要设置插值器，用来真实的模拟生活中的场景。  Interpolator （插值器）...

2159