I’ve got a parabola where the user can adjust the x-intercepts and vertex. That works no problem, I’m just positioning 3 points and using moveTo and curveTo. However, I need to extend the lines off the parabola past the x-intercepts and I can’t figure it out.
I tried to plot another point on either end of the parabola, but my math must be off, and it looks like I’m sticking two lines on the end of the parabola. I think I’ll have to get another mid-point and use a curve to in order to get the consistent curved look, but, without the math to calculate the points, it won’t matter how many points I add.
Here’s the code and the file is attached:
//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+")";
};
Thanks!!!