Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

In some ray casting algorithm I want to integrate the following integral:

$\int_{0}^{Z} \frac{c^x}{\|(\vec{o}+x \vec{d})-\vec{l}\|^3} dx$

  • $Z$ is a constant until which I want to integrate
  • $\vec{o}$ is the origin of the ray.
  • $\vec{d}$ is the direction of the ray.
  • $\vec{o} + x \vec{d}$ is the position of the ray at time $x$.
  • $\vec{l}$ is the position of a light.
  • $\|(\vec{o}+x \vec{d})-\vec{l}\|$ is the distance between the current position and the light.
  • $c^x$ is a weighting factor which I want to apply. When I move further away from the camera by increasing x, I want the weight to decrease ($c$ < 1).
  • $c$ is a constant value (like 0.9).

Solving it via a Riemann sum is not efficient enough on the Xbox. Therefore, I want to solve it analytically. However, as there is a norm of vectors involved together with some other ugly parts, I don't really know where to start solving this.

  • Is it possible to solve this integral analytically? (If yes, how?)
  • Is there a way to approximate this integral by using non-uniform step-sizes using some Riemann-style integration to increase efficiency of my current implementation?
  • Maybe some other solutions? It doesn't have to be exact; as long as it is not instable for small changes to $Z$ and it somehow approximates the integral, it should be fine since it is used in a game I am working on (where importance of performance is bigger than importance of correctness).
share|improve this question
    
The question whether this integral can be solved analytically isn't well-defined unless you specify $c^x$. –  joriki Apr 21 '11 at 14:13
    
c is a constant factor, (like 0.9) and x is the integration variable. –  Etan Apr 21 '11 at 14:15
    
I see. Then you've got "some" and "a" exchanged. It makes sense to say either "$c$ is a constant value" or "$c$ is some constant value", but it doesn't make sense to say "$c^x$ is some weighting factor", since you've actually specified it (namely $c^x$). –  joriki Apr 21 '11 at 14:31
    
Ok, now it should be "mathematically correct" ;-) –  Etan Apr 21 '11 at 21:36

1 Answer 1

up vote 4 down vote accepted

In general, this integral won't have an elementary 'closed-form' solution; the denominator is some value of the form $(ax^2+bx+c)^{3/2}$ and a few moments with the integrator at Wolfram Alpha suggests that there's no closed form for such an integral with the exponential weighting you want. I think you have the right idea with numerical evaluation, but Riemann sums aren't the best way of evaluating integrals; you should look at things like Simpson's Rule as a starting point, or go to a reference like Numerical Recipes for more adaptive mechanisms. In practice, though, you're going to have a hard time getting an accurate value for an integral like this with less than dozens of steps and evaluations, especially for rays that come close to the light where the denominator can grow large and varies rapidly.

share|improve this answer
    
What about changing the denominator to $(ax^2 + bx + c)$ - changing the exponent from 3 to 2? Ok, it's not physically correct, but the basic visual result will be acceptable. Or maybe changing the nominator to something like $\frac{1}{x+1}$. An analytical result is really necessary since a dozens of steps are just impossible in real time. So, approximations are really okay :-) –  Etan Apr 21 '11 at 22:56
    
Even doing that integral is going to involve square roots, exponentiation and computing the so-called Exponential Integral ( en.wikipedia.org/wiki/Exponential_integral )- in other words, more expensive special functions. I'd suggest 'popping the question' a level, making a Q about what you're using the integral to compute (something like a fog, I presume?) rather than the integral itself, and asking over at gamedev.SE... –  Steven Stadnicki Apr 21 '11 at 23:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.