How can I convert curveTo() to a list of Points?

前端 未结 3 1885
悲哀的现实
悲哀的现实 2021-01-02 06:46

Take the following AS3 that will draw a curved line using curveTo():

var line:Shape = new Shape();

line.x = line.y = 20;
line.graphics.lineStyl         


        
3条回答
  •  盖世英雄少女心
    2021-01-02 07:22

    From reading the actionscript documentation, I understand that the curveTo method in action script generates a quadratic Bezier curve.

    The curve consists of three "control points" that you specified in your code:

    control point 1 (p1) = (20,20)
    control point 2 (p2) = (200,200)
    control point 3 (p3) = (200,0)
    

    To interpolate a value along the curve at value u ranging from 0 to 1 (with 0 being the start point and 1 being the ending point) you can use what are called Bernstein polynomials. For a quadratic curve (your case) the polynomials are:

    B1 = (1 - u) * (1 - u)
    B2 = 2 * u * (1 - u)
    B3 = u * u
    

    Simply calculate these numbers for parameter value u and add together the control points multiplied by their corresponding Bernstein polynomials.

    point on curve at parameter *u* = p1 * B1 + p2 * b2 + p3 * B3
    

    So, for example, if you want to get 5 points along the curve, you calculate the points along the curve at parameter values 0, 0.25, 0.5, 0.75, and 1.0

提交回复
热议问题