2
$\begingroup$

I'm having this problem on some game I'm coding which I think it's just math and has nothing to do with coding, that's why I'm posting it here and I'm going to simplify the problem without describing anything related to the actual code. In case you want to take a look, please see this question on Stack Overflow: https://stackoverflow.com/questions/5822740/how-to-correctly-get-the-terrain-height-at-point-x-z-in-a-scaled-terrain

Let's say I want to draw a line on screen, with width w. To draw this line I need to do it in steps, sw, by default 1 unit steps. But I do allow this width to be scaled to any other value. After selecting the new width, dw, the new step needs to be calculated and I do it like this: sw = dw / w. With this, the line is properly scaled and I can draw it just fine.

Now, for a given x of that line I need to do some other calculations. Since I allowed the line to be scaled and it's not the original width. I need to calculate the real x, nx, before anything else. I just need to work on the step value calculated before, like this: nx = x / sw.

This will give me exactly the right nx value I'm looking for. Everything's working so far.

Now, my real problem is when I need to introduce a little change to the step calculation. Instead of calculating the step like I said before (sw = dw / w) I need to calculate it like this: sw = dw / (w - 1).

The problem I'm actually having is in the next step. Given x, how do I correctly calculate nx as I did before? Math is not my strong suite and I tried many things that I would think were right but it was mostly trial and error. Suffice to say, nothing worked.

  • 0
    BTW, the expression is "strong suit" (comes from card games like bridge), not "strong suite". I stared at the phrase for a long time before I realised what was bothering me. :-)2011-04-29

2 Answers 2

1

I am not sure that I understood your question correctly, but what makes you think that the very same expression

nx = x / sw 

does not work?

After all, the only change is that you replaced an arbitrary value $w$ by an arbitrary value $w-1$.

  • 0
    @Nazgulled: Why doesn't it work as ex$p$ected? You want to get a total "width" (which it seems is more appropriately called "length", but nevermind) of `x`, and each step is `sw` units, so the number of steps `nx` is `nx = x / sw`, since `sw` units `x/sw` times will give `x`. So this expression is the logically correct one — assuming that I've understood the rest of your question. Or else clarify.2011-04-29
0

Might it be that $w$ sometimes equals one ? Then $w - 1$ would yield zero and trigger a division by zero error. Else, it'd help if you told us exactly what kind of error you're getting. I, for once, have no clue.

Good luck with that code!

  • 0
    I never mentioned any kind of error, there's no error.2011-04-28