Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

stack0s

Member
  • Content Count

    3
  • Joined

  • Last visited

Awards


This user doesn't have any awards

About stack0s

  • Title
    Newbie
  1. Your calculation for findB is wrong... it should be return y - (m*x) it's not division it's subtraction but other than that this helped me because I was having a hard time with the intersection part which you did very well. I translated it back to a program in actionscript 2.0 that runs once and prints then exits. Here it is... var test = true; onEnterFrame = function () { if (test) { var PI = 3.14195; //calculates pi, 3.14159 //data set 1 var x1 = 10; var y1 = 23; var x2 = 65; var y2 = -17; //data set 2 var x3 = 49; var y3 = 25; var x4 = 7; var y4 = -12; var m1 = findM(x1, y1, x2, y2); var m2 = findM(x3, y3, x4, y4); var a = findB(y1, x1, m1); var b = findB(y3, x3, m2); /* view work so far */ trace("EQUATION 1: "); printLineEqu(m1, a); trace("EQUATION 2: "); printLineEqu(m2, b); /* done */ //parallel line check if ((m2-m1) == 0) { trace("both lines are parallel."); return 0; //exit if out of range } //calculate theta var theta = findTheta(m1, m2); if ((theta<0) || (theta>(PI/2))) { trace("theta: "+theta); trace("angle out of range."); return 0; //exit if out of range } //find intersections, if all is well var Xintersection = findXintersection(a, b, m1, m2); trace("X intersection: "+Xintersection); var Yintersection = findYintersection(a, b, m1, m2); trace("Y intersection: "+Yintersection); test = false; } }; //used for plotting on ti-89 as check, plug and chug function printLineEqu(_m:Number, _b:Number) { if (_b<0) { trace("Y = "+_m+"*x"+_b); } else { trace("Y = "+_m+"*x+"+_b); } } //find theta function findTheta(_m1:Number, _m2:Number):Number { _theta = (_m1-_m2)/(1+(_m1*_m2)); _theta = Math.abs(_theta); //absolute value _theta = Math.atan(_theta); //inverse tan return _theta; } //find the y intersection function findYintersection(_a:Number, _b:Number, _m1:Number, _m2:Number):Number { return ((_a*_m2)-(_b*_m1))/(_m2-_m1); } //Fine the x intersection function findXintersection(_a:Number, _b:Number, _m1:Number, _m2:Number):Number { return (_a-_b)/(_m2-_m1); } //find slope function findM(_x1:Number, _y1:Number, _x2:Number, _y2:Number):Number { return (_y2-_y1)/(_x2-_x1); } //find b function findB(_yB:Number, _xB:Number, _mB:Number):Number { return (_yB-(_mB*_xB)); } //find X intercept function findXintercept(_m:Number, _b:Number):Number { return ((0-_b)/_m); } //find Y intercept function findYintercept(_m:Number, _b:Number):Number { return ((_m*0)+_b); } Thanks alot!
  2. Hey thanks this is pretty helpful! But I am trying to find the intersection of two line segments...
  3. Hi I am trying to use some Actionscript 2.0 for this problem but if you can abstraction to basic algebra I think my intentions are clear... I am simply trying to calculate some X Y intercepts but am getting poor results... I studied the algebraic formula to derive this program However! I am still getting the wrong answers. Can someone please help me fix this? Here is my code test = true; var x1 = 3; var y1 = -12; var x2 = 16; var y2 = -10; var x3 = 8; var y3 = -15; var x4 = 12; var y4 = -1; function determineXY():Void { //Solve //initiate lines //line1 //m var line1m = ((y2-y1)/(x2-x1)); var line1msave = line1m; //b var line1b = (y1-(line1m*x1)); var line1bsave = line1b; //line2 //m var line2m = ((y4-y3)/(x4-x3)); var line2msave = line2m; //b var line2b = (y3-(line2m*x3)); var line2bsave = line2b; //Solve X //determine m(x) if (line1b>=0) { line2m = Math.abs(line2m)*1; } if (line1b<0) { line2m = Math.abs(line2m)*-1; } //determine b if (line2msave>=0) { line1b = Math.abs(line1b)*1; } if (line2msave<0) { line1b = Math.abs(line1b)*-1; } xint = ((line1b+line2b)/(line1m+line2m)); //Solve Y yint = ((line2msave*xint)+line2bsave); } function getXYIntercept(inputX1:Number, inputY1:Number, inputX2:Number, inputY2:Number, inputX3:Number, inputY3:Number, inputX4:Number, inputY4:Number):Void { x1 = inputX1; y1 = inputY1; x2 = inputX2; y2 = inputY2; x3 = inputX3; y3 = inputY3; x4 = inputX4; y4 = inputY4; determineXY(); //draw (this is just to visual the results) _root.createEmptyMovieClip("holder", 1); holder.lineStyle(2, 0x000000, 100); holder.moveTo(x1, y1); holder.lineTo(x2, y3); holder.moveTo(x3, y3); holder.lineTo(x4, y4); intersection._x = xint; intersection._y = yint; } onEnterFrame = function () { if (test) { getXYIntercept(x1,y1,x2,y2,x3,y3,x4,y4); trace(xint); trace(yint) } test = false; }; This is it... only thing not in the code is the movie clip referenced above
×