A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: y = m*x+b ( something about equations of lines )

  1. #1
    Member
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    44

    y = m*x+b ( something about equations of lines )

    Hey Flashkit!!!

    I am currently reading a book on Flash MX game design entitled "flash mx game design demystified" and on pg. 111 under the heading <b>Line-Line collision Detection</b> the following formula is presented:

    y=m*x+b

    m = slope of the line
    b = y-intercept ( spot where the line intersects the y-axis )

    can anyone tell me what this equation means and point me to some kind of web page that will explain this in comprehensive detail?

    Thanx a lot.
    "Always telling the truth means never having to remember anything"

  2. #2
    madskool.wordpress.com brutfood's Avatar
    Join Date
    Apr 2002
    Posts
    469
    Ok, I came to the maths forum because this is my 343rd post!

    Any mathematician will tell you 343 is a nice number. A palindrome, and seven cubed! - I'm sure it has loads of other neat qualities too.

    Ok, equation of a straight line: Take a ruler, and a piece of graph paper. Draw a vertical line down the centre on the page, and draw a horizontal line through it half way down the page. Now you have two axis that meet in the centre or origin (0,0).

    Ok, now calibrate your axis. The horizontal axis should go from -4 to +4, and if your paper is A4 portrait, you should be able to manage a larger range on the y axis. Just ensure zero is at the origin

    Now consider the equation y=2x-1

    when x=-5, y=-11
    when y=-4, y=-9
    x=-3, y=-7
    x=-2, y=-5
    x=-1, y=-3
    x=0, y=-1 (so indeed the intersection with the y axis is -1)
    x=1, y=1
    x=2, y=3
    x=3, y=5
    x=4, y=7
    x=5, y=9

    Now plot these points on your graph, and see for yourself that the gradient (change in y divided by change in x) is 2.
    AIR, ActionScript 3, Flex and Flash expert and freelance developer

  3. #3
    Member
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    44
    Okay that's great and everything but how does it relate to line-line collisions in the big picture in regard to Flash MX? What do you mean by "gradient is always 2".

    How does that help you determine when two lines are intersecting?

    P.S I thought I was pretty good at maths
    "Always telling the truth means never having to remember anything"

  4. #4
    Member
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    44
    Oh no wait I get it. This is the equation for a straight line. But the equation I gave you was: y=m*x+b. Where m is the slope of the line and b is the y-intercept.

    I STILL DON'T GET IT. A bit more basic if you can???
    "Always telling the truth means never having to remember anything"

  5. #5
    madskool.wordpress.com brutfood's Avatar
    Join Date
    Apr 2002
    Posts
    469
    ok, the example I gave was y=2x-1.

    This is y=mx+b, where m=2 and b=-1.

    (btw, most text books would say y=mx+c, not b)

    ok, suppose I wish to know where y=2x-1 intersects with y=3x+2

    They intersect where y's are equal and x's are equal.

    2x-1=3x+2
    x=-3.

    substitute this into either equation and you get y=-7

    so these two line intersect at (-3,-7)
    AIR, ActionScript 3, Flex and Flash expert and freelance developer

  6. #6
    Member
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    44
    Ok i guess i almost understand it but the equation of a line really buffles me. Could you please give me a "REAL BEGINNER'S COURSE" ( just pretend you're talking to a primary school kid ).

    y=mx+b,

    still don't understand it.
    "Always telling the truth means never having to remember anything"

  7. #7
    madskool.wordpress.com brutfood's Avatar
    Join Date
    Apr 2002
    Posts
    469
    Ok, first of all, these lines are infinately long. So unless the line is vertical, (and has the equation y=b). For every value of x, going along the x-axis, there will be a (single) value of y.

    The equation that converts an 'x' value to a 'y' value is the equation of the line.

    What algebra, geometry or maths have you done? It may help if you tell me what stage you're at, and I may be able to explain it in terms of stuff you know.
    AIR, ActionScript 3, Flex and Flash expert and freelance developer

  8. #8
    Member
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    44
    Okay I know what alebra IS. And I know what a line is. I understand that lines have starting and ending points (x, y, x,y) and all that. But I'm not a mathematical genius.

    I mean I understand that each line has an x, y starting point but how can you find the y value from the x value? Isn't that impossible? I mean if x is a certain value then y can be any value right? So how can you have an equation to find the y point?

    I am doing Yr. 10 at the moment but maths at my school hasn't reached stuff like the line equation.
    "Always telling the truth means never having to remember anything"

  9. #9
    madskool.wordpress.com brutfood's Avatar
    Join Date
    Apr 2002
    Posts
    469
    y=mx+c doesn't specify start and end points. If your lines have a beginning and an end, you have to specify the coordinates of these seperately. That's more involved, so let's stick to infinite length lines, because they're easier:

    For a line, if x is a certain value, there is only ONE corresponding value for y. Furthermore, this value is unique. Unless the line is vertical (y=c).

    We say that there is a RELATION between x and y.

    There are lots of relations in maths and physics. For example, the relation between the radius of a circle, and it's area:-

    Area = Math.PI*r*r

    You would agree here that if r has a (positive real) value, Area has one unique value, not many. Same with a line.

    Or to put it another way: In our whole 2D universe, x and y are allowed to range over any value. They are unrelated - like you described.

    But as soon as we describe something inside this space, then the description of this effectively narrows down the possibilities, so x and y are contrained to only assume certain values, which have some relation to each other. The relation throws out everything else.

    If I describe a point (1,2), then I have a description that has narrowed down an infinate universe of points to just one (1,2).

    If I describe the line y=2x-1, then I have a description/relation that has narrowed down all the points in my universe, to just the ones that lie along the line.

    Any other mathematicians here think they can explain it better than me?
    AIR, ActionScript 3, Flex and Flash expert and freelance developer

  10. #10
    Member
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    44
    1) what is the exact x value of a line? It is not the start or end point so what is it? Is it by any chance how far along the x-axis the line goes?

    2) same as above but for the y value, is it how far it goes along the y-axis?

    3) If what I said above is true then it's like an imaginary triangle yes? So if we figure out the y and x axis we can know how long the line is?

    "I know I'm having a lot of difficulties with this but I am not as advanced in maths as you so this stuff really has to get 'hammered in'"
    "Always telling the truth means never having to remember anything"

  11. #11
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Any other mathematicians here think they can explain it better than me?
    hmm, not sure if I count as a mathematican or if I can explain better, but i'll give it a try

    if you know the equation of the line, say

    y = 5x + 4

    it allows you to pick any x point along the x axis (4, 12, 172, -8, 3.14 etc anything you like) and find the y value the line is passing through when x is that value. so for the above example,

    y = 5x + 4

    at the point x = 2 you have,

    y = 5 * 2 + 4
    y = 14

    so the line passes through the point (2, 14)

    there are no end points for the line, x can go on forever positively and negatively. however you can select a range of values for which you want to look at the line for example you may decide you are only interested in the line between x = -2 and x = 2

    you could also rearrange the equation of the line to allow you to find where on the x axis you are at a particular y value,

    again, y = 5x + 4

    reaarranging to find x,
    x = (y - 4) / 5

    lets say we want to know where along the x axis we would be on this line at the point y = 14,

    x = (14 - 4) / 5
    x = 2

    that is the point (2, 14) (the same as before )

    another possibility is that you don't know the equation of the line, instead you just know 2 points on the line (from these points you can calculate the equation) y = mx + c (we will find what m and c are)

    lets take the points (1, 9) and (2, 14) and find the equation of the line (although from the previous examples you may guess the solution )

    the gradient of the line can be found by dividing the difference in the y values at the 2 points by the difference in the x values,

    gradient m = (14 - 9) / (2 - 1) = 5

    so now we know y = mx + c for this case is y = 5x + c

    we also know some points. so we can pick one of these (1, 9) to give

    9 = 5 * 1 + c

    c = 4

    so the equation of the line is

    y = 5x + 4

    back to where we started agian, hope this helps

  12. #12
    madskool.wordpress.com brutfood's Avatar
    Join Date
    Apr 2002
    Posts
    469
    Originally posted by kostanzas200
    1) what is the exact x value of a line? It is not the start or end point so what is it? Is it by any chance how far along the x-axis the line goes?

    2) same as above but for the y value, is it how far it goes along the y-axis?

    3) If what I said above is true then it's like an imaginary triangle yes? So if we figure out the y and x axis we can know how long the line is?
    A1. There's a difference between variable in a computer program, and variables in mathematics. In a computer program, at any instant, a variable such as x will have a value, (or null).

    However, in mathematics it is a differenct concept -and this is the key to understanding this:-

    When we look at an equation such as y=mx+c, x and y instantaneously flow over ALL THEIR POSSIBLE VALUES. They are all of these possibilities at once, not just one. They are not instanciated to a value, unless we fix one of them to determine the other.

    A2. For y=mx+c, unless the line is vertical or horizontal, it goes from minus infinity to plus infinity along both axis. The line has infinite length.

    A3. To specify a line with finite length is more involved. Consider catbert's line that goes between end-points (1,9) and (2,14).

    The equation of this line is: y=5x+4
    But because this line is NOT infinite, we also need to say:

    1<= x <= 2

    This inequality tells us that x only ranges over all the values between 1 and 2.

    - So we have both the equation of the line and an inequality. These are what we use use if we were to write a function to detect the intersection of finite length lines.
    AIR, ActionScript 3, Flex and Flash expert and freelance developer

  13. #13
    Junior Member
    Join Date
    Jul 2002
    Posts
    25
    SIDE NOTE:
    For those of you who are wondering, "gradient of a line" is synonymous with "slope of a line".
    Last edited by muckyMuckMan; 03-18-2003 at 12:58 AM.

  14. #14
    Life Member
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    87
    Hope I cover everything. To Start With:
    First of all its y = mx+c not b.
    Also a line has a (X1, Y1) point connected to a (X2 , Y2) point.
    This means that 'm' in y=mx+c is
    m = (Y2-Y1) / (X2-X1)
    - (m being the gradient or the steepness of the line (like a hill).)
    - (and just for fun, m=tan(Angle), this can be eplained in a triangle diagram.)

    I think what you are confused about is how the formula can relate to the line? Well you get the fomula from the two points on the line which have the x1,x2,y1,y2. Also to find the full formula you will have to find c which is when x = 0.

    Anyways the relation between this formula and line intersection testing (Line-Line collision Detection) is that if you have two lines then they have two different (y=mx+c) equations and you can find where and if these lines intersect with each other. (You should know this in y10.)

    So to find the point where both lines intersect you do simultaneous equations. First of all if you have two equations;
    y1 = 2x + 4 and y2 = 3x + 6 you want to find the intersect.

    so now put (For x value of intersection)
    ------------
    y2 into y1 so that; 3x + 6 = 2x + 4
    => 3x+2 = 2x
    => 3x - 2x = -2
    => X = -2
    Now so far we have our x value
    --------------

    now for to get the y value of intersection
    ---------------
    Just put your derived x value into into one of the y1 or y2 equations to get a y value.
    For y1.
    Y = 2(-2)+4
    Y = 0
    ----------

    So the intersection just happens to be at (-2,0)
    ------
    I don't have time to explain the rest but just for fact;
    -------------
    Distance between two points = sqrt[(x2-x1)^2 + (y2-y1)^2]
    perpendicular lines are m1*m2 = -1
    y-y1 = (y2-y1)/(x2-x1)(x-x1)
    y-y1 = m(x-x1)

    The pic i made shows the equations y1,y2 intersecting and these equations can be taken from line points.
    Attached Images Attached Images

  15. #15
    Member
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    44
    Thanx. I guess I'll have to wait till furthur in Yr. 10 to learn this . It seems hope less now.
    "Always telling the truth means never having to remember anything"

  16. #16
    exclusive member ( V I P ) tiGRAN=-2001's Avatar
    Join Date
    Aug 2001
    Posts
    434
    I think any math teacher at your school would gladly explain this to you and maybe give you a handout, its very simple once you get to it.

    If youre on a mac, it might have a graphing calculator, try graphing
    Y=MX+C with different values for M, x and c. This will help you understand better.

    One more thing, a basic algebra book at the library should have a nice section dedicated to y=mx+c

    good luck

  17. #17
    Member
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    44
    Thanx. I have been trying to ask some maths teachers at my skool but never got around to doing it.

    Thanx for suggesting a look in the algebra section. Personally I always thought it was in the trigonometry section. Thanx a lot.

    my web site by the way, all you guys, is:
    http://band-of-brothers.tripod.com
    "Always telling the truth means never having to remember anything"

  18. #18
    Senior Member
    Join Date
    Mar 2002
    Posts
    183
    I happened to have always learned y=mx+b.

    Where do you guys live, maybe its a regional thing. Regional like gradient/slope.haha

  19. #19
    Member
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    44
    Ye Minger I guess I was never the little geek at skool. Sorry.
    "Always telling the truth means never having to remember anything"

  20. #20
    Member
    Join Date
    Feb 2003
    Posts
    96

    hey

    Have you had any basic algebra in school? How old are you?
    Matt

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