2d game geometry

andrewjb123

New member
Joined
Jan 10, 2017
Messages
4
I have the following problem:

height question.jpg

I have asked the same question here: http://math.stackexchange.com/quest...s/2089369?noredirect=1#comment4294547_2089369

and have used the formula given to work out 8 and it is the correct value. But im really struggling to understand how each part of the formula was worked out.

ideally what i want is to be able to plug in the value of 2 height 2, 15 height 5 - and give an index of 8 (or other) which will give me the corresponding height.
 
Which part is confusing to you? Please be specific. Thank you! ;)


well, I’ve been reading here how to work out the equation of a straight line,


http://mathonweb.com/help_ebook/html/graphs_2.htm


and looked at these particular sentence


Find any two points, (x1, y1) and (x2, y2), on the line and substitute their coordinates into the following formula to get m:


this is easy because i know what x1, y1 and x2, y2 are as values, so i can find m easily.


then it comes to calculating b, and i can’t see how on earth i can calculate b, it says:



  • Get b from inspection of the y intercept of the graph.
well how can i do this in an equation without having to visually see the y intercept on a graph as show in the graph in their example, i can visually see it, but i want to be able to calculate it as i want to create a function in code which i can plug in the values (any values not just the ones in my example) so i can calculate depth in a 2d scene? is it possible?


I think (and correct me if I’m wrong) but this is how he got + 20 ? (+ 20 is + b)
 
h = 3/13i - 6/13 + 26/13

in this part of the equation how is 26/13 found? I can see that 26/13 = 2 - but what if i dont know that 20+6 / 13 = 2 ? how would i get the 20 part?
 
Last edited:
think i have nailed it

var
h1 = 2;
var i1 = 2;
var h2 = 5;
var i2 = 15;
var i = 8;

var calc1 = h2 - h1; // 3
var calc2 = i2 - i1; // 13
var calc3 = calc2 * h2; // 13*5=65
var calc4 = calc1 * i2; // 45
var calc5 = calc3 - calc4; // 20
var calc6 = ((calc1 * i) + calc5) / calc2;
 
Top