A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Generate parabola?

  1. #1
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929

    Generate parabola?

    I need to create a parabola between 3 points which are controlled by a slider:
    the two points where the parabola crosses the x plane
    the y location of the vertex of the parabola

    I've tried adapting the code in:
    http://www.flashkit.com/movies/Scrip...1568/index.php
    but that doesn't let you set the x points.

    I've got the code to set the location of the 3 points, but not sure what formula/convention I can use to draw the parabola between the points and have the ends extend across the grid?

    Anyone have any idea what formula I might use?

    See the attached file to see what I'm talking about...
    Last edited by flashpipe1; 08-27-2007 at 08:37 AM.
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  2. #2
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929
    Got it...sort of...I can graph the parabola by adding the following to the onEnterFrame script:

    Code:
    clear();
    	lineStyle(1, 0, 100);
    	moveTo(this.p1._x+this._x, this.p1._y+this._y);
    	curveTo(this.p0._x+this._x, (this.p0._y*2)+this._y, this.p2._x+this._x, this.p2._y+this._y);
    but I can't figure out how to extend the ends of the parabola to continue on to infinity??

    HELP!!!!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  3. #3
    When in doubt ask Eager Beaver's Avatar
    Join Date
    Feb 2007
    Location
    Planet Earth
    Posts
    911
    Using the same lineTo, curveTo, class, I have developed this FLA.
    The parabola is connecting only dots at the beginning (x0,y0), and
    dots at ending (x2,y2). It does not connect the dot at (x1,y1).
    I don't know why? Also, the curve does not extend beyond (x2,y2).
    I am not able yiew the parabola created by you since the FLA was not attached.
    Last edited by Eager Beaver; 08-19-2007 at 02:23 PM.
    <signature removed by admin>

  4. #4
    When in doubt ask Eager Beaver's Avatar
    Join Date
    Feb 2007
    Location
    Planet Earth
    Posts
    911
    I have to post again in view of the ten minute time limit!
    In this connection please see this thread in these forums. A further link to another thread was also given in one of the posts.
    I think the solution lies in solving bezier quadratic curve equation of the type:
    y=a*x*x+b*x+c
    for the values:
    start point: (x0,y0)
    intermediate point: (x1,y1)
    third point: (x3, y3)
    The curve can then be extended beyond (x3,y3) to any value upto say infinity.
    Last edited by Eager Beaver; 05-03-2007 at 04:19 AM.
    <signature removed by admin>

  5. #5
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929
    Hmmm...my fla is attached in my first post...

    I'm pretty sure I know what I need to do in order to extend my parabola using the convention I've got set up. I think I need to plug a large y value (like 1000 or -1000, depending on the -/+ of the a value) into an equation to give me the corresponding x value and then draw a line from the current end of the parabola to the new point...I'm just not sure how to change the equation to give me the x value and how to get that on both sides of the parabola...
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  6. #6
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929
    Here's the path I'm going down now...basically, since I need the user to be able to adjust the x-intercepts and vertex, I'm trying to fake the extents of the parabola by plotting the x and y of another point and drawing lines between the ends of the parabola and the extended points.

    However, my math is off and it looks like lines shooting off the parabola...

    Here's the code, and the file is attached:

    Code:
    //set initial slider values
    sliderPara_p0.slide._x = 20;
    sliderPara_p1.slide._x = -5;
    sliderPara_p2.slide._x = 5;
    para_mc.onEnterFrame = function() {
    	//calculate vertex y
    	this.p0._y = this._parent.sliderPara_p0.slide._x*5;
    	//calculate x-intersects
    	this.p1._x = this._parent.sliderPara_p1.slide._x*5;
    	this.p2._x = this._parent.sliderPara_p2.slide._x*5;
    	//figure x of vertex based on center of p1 and p2
    	if ((this.p1._x)<(this.p2._x)) {
    		this.p0._x = (this.p2._x/2)-(this.p1._x/-2);
    	} else {
    		this.p0._x = (this.p1._x/2)-(this.p2._x/-2);
    	}
    	//display values in slider text fields
    	this._parent.display_a = Math.round(((this.p0._y*2)/100)*10)/10;
    	this._parent.display_p = Math.round(((this.p1._x*2)/100)*10)/10;
    	this._parent.display_q = Math.round(((this.p2._x*2)/100)*10)/10;
    	//calculate lines
    	tmpA = (this.p1._x-this.p0._x)*2;
    	this.p10._x = tmpA+this.p1._x;
    	this.p10._y = (this._parent.display_a*-1)*((tmpA/2-this._parent.display_p)*(tmpA/2-this._parent.display_q));
    	tmpA = (this.p2._x-this.p0._x)*2;
    	this.p20._x = tmpA+this.p2._x;
    	this.p20._y = (this._parent.display_a*-1)*((tmpA/2-this._parent.display_p)*(tmpA/2-this._parent.display_q));
    	this.clear();
    	//draw parabola
    	this.lineStyle(1, 0, 100);
    	this.moveTo(this.p1._x+this._x, this.p1._y+this._y);
    	this.curveTo(this.p0._x+this._x, (this.p0._y*2)+this._y, this.p2._x+this._x, this.p2._y+this._y);
    	//draw lines
    	this.moveTo(this.p10._x+this._x, this.p10._y+this._y);
    	this.lineTo(this.p1._x+this._x, this.p1._y+this._y);
    	this.moveTo(this.p20._x+this._x, this.p20._y+this._y);
    	this.lineTo(this.p2._x+this._x, this.p2._y+this._y);
    	//text for equation
    	if (this._parent.display_p>0) {
    		temp_p = "- "+this._parent.display_p;
    	} else if (this._parent.display_p<0) {
    		temp_p = "+ "+(this._parent.display_p*-1);
    	} else if (this._parent.display_p == 0) {
    		temp_p = "- 0";
    	}
    	if (this._parent.display_q>0) {
    		temp_q = "- "+this._parent.display_q;
    	} else if (this._parent.display_q<0) {
    		temp_q = "+ "+(this._parent.display_q*-1);
    	} else if (this._parent.display_q == 0) {
    		temp_q = "- 0";
    	}
    	this._parent.display_function = "y= "+this._parent.display_a+"(x "+temp_p+")(x "+temp_q+")";
    };
    Anyone have any ideas on how to fix this??

    Thanks!!!
    Last edited by flashpipe1; 08-27-2007 at 08:37 AM.
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center