   Cone/Ray
  Hi,So, given:-Cone C, defined by vertex point A, vertex angle θ, along the axis defined by vector v-Point B and vector y.I need a function that gives the distance a ray from B along y travels through Cone C.  Ideally, it would be nice to be able to also specify a cone's-radius-dependent density function, to weight the distance the ray travels through it.  At the moment, I'm not sure where to start.  Could one try transforming all the data so that the cone's axis v lies along the vertical axis?Help?Thanks,-G   
  The 'distance' function seems like it'd be fairly straightforward - just intersect the ray with the cone and compute the distance between the entry and exit points, if any. (Or is the intersection part what you're looking for info on?)Keep in mind that if the cone is unbounded (i.e. no cap), the distance could be infinite.As for the density function, are you talking about each (infinitely thin) slice of the cone having a different density? If so, it seems you could compute the (scalar) orthogonal projection of the entry and exit points onto the cone axis, compute the densities associated with these two 'slices', and then compute the 'total density' over the course of the ray's traversal of the cone interior using some simple calculus. (That is, assuming I'm understanding what you're after.)   ;Quote:The 'distance' function seems like it'd be fairly straightforward - just intersect the ray with the cone and compute the distance between the entry and exit points, if any. (Or is the intersection part what you're looking for info on?)yep.Quote:Keep in mind that if the cone is unbounded (i.e. no cap), the distance could be infinite.This makes me think of something else.  I need to know how far it is along the ray to both cone intersections.  The ray stops after a certain length (let's call it "l"), so the distance through the cone should only be evaluated to that length.Quote:As for the density function, are you talking about each (infinitely thin) slice of the cone having a different density?Not quite.  The center of the cone (along the axis) is the most dense, with density reaching 0 at the furthest radius.  The falloff is a function of the radius, and might not be linear.  Thanks, G   ;Quote:Original post by GeometrianQuote:The 'distance' function seems like it'd be fairly straightforward - just intersect the ray with the cone and compute the distance between the entry and exit points, if any. (Or is the intersection part what you're looking for info on?)yep.'Yep', as in, 'Yep, I'm looking for information on ray-cone intersection'? (Sorry - just want to make sure we're answering the right questions :)Quote:This makes me think of something else.  I need to know how far it is along the ray to both cone intersections.  The ray stops after a certain length (let's call it "l"), so the distance through the cone should only be evaluated to that length.So then is it basically a segment-cone intersection that we're talking about? If so, that seems easy enough - if the segment doesn't extend all the way through the cone, the distance will simply be the distance from the entry point to the segment endpoint.Quote:Not quite.  The center of the cone (along the axis) is the most dense, with density reaching 0 at the furthest radius.  The falloff is a function of the radius, and might not be linear.Hm, that sounds a little more complicated.Still, I think it can probably be solved more or less as I described earlier. The density is a function of distance along the cone axis, the graph of which will be a triangle, a parabola, or some other similar shape. Once you've determined where along the cone axis the segment intersection begins and ends, you have a vertical 'slice' of the graph; the area under the curve for this 'slice' is the total amount of 'material' that the segment will pass through. Or something like that :-|Just out of curiosity, what's the context of the problem?   ;Quote:'Yep', as in, 'Yep, I'm looking for information on ray-cone intersection'?)"Yep" :)Quote:So then is it basically a segment-cone intersection that we're talking about? If so, that seems easy enough - if the segment doesn't extend all the way through the cone, the distance will simply be the distance from the entry point to the segment endpoint.Righto--so how to measure that distance?Quote:Still, I think it can probably be solved more or less as I described earlier. The density is a function of distance along the cone axis, the graph of which will be a triangle, a parabola, or some other similar shape. Once you've determined where along the cone axis the segment intersection begins and ends, you have a vertical 'slice' of the graph; the area under the curve for this 'slice' is the total amount of 'material' that the segment will pass through. Or something like that :-|Yes, I thought of that.  Of course, the ray may not be perpendicular (or perpendicular-skew) to vector v.  Hence, the ray may pass through a different form of the function, which makes it tricky.Quote:Just out of curiosity, what's the context of the problem?I'm adjusting my shadow volume volumetric lighting (here) to work better.  (I explain the technique more clearly in my second post).  Right now, the "integration function" is a hack--basically a depth peel of a light cone, which of course is inaccurate, costly, and can't take density into account.  To get single scattering in the medium around the object (the lit portion, which was ignored), I need an accurate measure of the distance.  I'm currently using a geometric approach (think using massive OpenGL blending to do a Riemann sum to measure the distance = slow) on this technique in conjunction with my new realtime volumetric caustics to get (here and here).  It's quite fast, believe it or not, but the accumulation stage it would be about 511 times faster with an actual integral . . .Thanks,-G   ;Quote:Original post by GeometrianQuote:'Yep', as in, 'Yep, I'm looking for information on ray-cone intersection'?)"Yep" :)Here is a PDF by Dave Eberly on the subject (there is accompanying code elsewhere on the site). It looks like the algorithm and code are for an unbounded cone, but it should be fairly straightforward to adapt the code for the case of a capped cone.Quote:Quote:So then is it basically a segment-cone intersection that we're talking about? If so, that seems easy enough - if the segment doesn't extend all the way through the cone, the distance will simply be the distance from the entry point to the segment endpoint.Righto--so how to measure that distance?Can you just compute the Euclidean distance between the start and end points?If you're looking for something more performant, and if the segment direction vector is unit length, you could just compute the distance as t2 - t1, where t1 and t2 are the parametric values corresponding to the start/entry and end/exit points for the segment, respectively.Quote:Yes, I thought of that.  Of course, the ray may not be perpendicular (or perpendicular-skew) to vector v.  Hence, the ray may pass through a different form of the function, which makes it tricky.Yeah, what I described earlier doesn't fully answer the question. If I figure out what's missing, I'll post back :)   ;  Now that I've read your other threads, I see that I misunderstood the 'density' aspect of the problem, so never mind what I posted about that.Maybe the cone intersection reference will be of some use though...   ;  Definitely!  I'm having trouble porting the intersection code to GLSL, (or Python), but it looks to be what I need.   ;  Not sure what was discussed in the other threads but have you thought about considering the cone just a line (oriented the same way as the cone of course...) and doing a "closest point on line to line" test?There might be a couple small hurdles, but it seems like this would get you a lot of the way there.   ;  That's interesting, but unfortunately, I don't think it would work.  It could be interesting for a boolean intersection test, but I need to find the distance the ray travels through the cone, which means finding the actual intersections and finding lengths, I think.   