Calculate the z-range of a light

Started by
9 comments, last by 51mon 17 years, 5 months ago
I have a light that is built up by a position and direction in 3-dimensional cartesian space; and an outline function in 2 dimensions. These 3 factors constitute a spherical shape where the light affecting geometry. Now I want to know the range of the depth, i.e. the highest and lowest z-value. How do I do that? The outline function is y = sqrt( (x/C)^(2/3) – x^2 ), where C is a constant. Thanks [Edited by - 51mon on November 13, 2006 5:56:38 PM]
Advertisement
I don't really understand what you are trying to do, I think you should try to make it a little more clear. Set an example about how your light should look like once is rendered and maybe people can help you a little better.

Let me see if I'm getting what you are saying, the outline function is for shading? Or is it the shape of the light ray?

Really don't understand.
Marco Tapia
Quote:Original post by mvtapia
I don't really understand what you are trying to do, I think you should try to make it a little more clear. Set an example about how your light should look like once is rendered and maybe people can help you a little better.

Let me see if I'm getting what you are saying, the outline function is for shading? Or is it the shape of the light ray?

Really don't understand.


Sorry
I try to explain better. The function constituate a bow shaped path. This path is sweaped around the direction vector and form the light mesh (it's like the "Lathe" modefier in 3dsmax). Now I want to know the min / max z-values of the mesh. The ligth mesh is for shading (deferred rendering).
sorry bad post

[Edited by - mvtapia on November 13, 2006 8:14:08 PM]
Marco Tapia
Quote:Original post by mvtapia
If this is a spot light type like so:

xxxxxxx
xx xx
xx xx
x + x

x = bow
+ = light direction into screen

or if like the picture you have there


xxxx
xx xx
xx xx
x x
------------->

x = bow
-> = light direction

I will try to explain, if is the second one the you have to figure out how the sweeping is going to be done, if is going to be a perfect circle or elipse y both cases you have to just add the circle equation of z in terms of xy.
in case of the first one you already have the bell shape, you only need to know the attenuation wich will give you your z term. z max.
I suppose you are talking about the second one so please let me know if I'm on the right track.


I allready have the shape and it has a spherical look, the second case.
First you have to put the position and the direction in the equation, other wise you will draw from zero and in the same direction for all your lights.
Now it seem that the term you have as x is what you are asking. you already have the depth of the light, you are just looking at it in 2D. Now, since you are saying that this is a spherical shape, this means that your Z term should be angle dependend. use the circle equation in terms of zy and put it with your current equation.

(z - h)2 + (y - k)2 = r2

h and k are the circle center which in this case should fall in the direction vector.
r is the y value form you current equation that will be the radius for a give x.

so you should do this, first calculate the y, to find you radius for a given x value. then apply the circle equation to find the 3d position.

(z - h)^2 + (y - k)^2 = (x/C^(2/3) - x^2 )

that should be your equation, I think.
Let me know if it works.
Marco Tapia
Quote:Original post by mvtapia
First you have to put the position and the direction in the equation, other wise you will draw from zero and in the same direction for all your lights.
Now it seem that the term you have as x is what you are asking. you already have the depth of the light, you are just looking at it in 2D. Now, since you are saying that this is a spherical shape, this means that your Z term should be angle dependend. use the circle equation in terms of zy and put it with your current equation.

(z - h)2 + (y - k)2 = r2

h and k are the circle center which in this case should fall in the direction vector.
r is the y value form you current equation that will be the radius for a give x.

so you should do this, first calculate the y, to find you radius for a given x value. then apply the circle equation to find the 3d position.

(z - h)^2 + (y - k)^2 = (x/C^(2/3) - x^2 )

that should be your equation, I think.
Let me know if it works.


It's night in my part of the world so I'm gonna check it tomorrow, but thanks.
Generalize the notion of a function to an arbitrary 2D basis. Usually you have the implied basis vectors i = (1,0) and j = (0,1), so the set of points belonging to a function is x*i + f(x)*j. Now let i and j be an arbitrary basis. In this case, project your direction vector D onto the XZ plane. Define R = sqrt(Dx2 + Dz2), and let i = (Dx/R,Dz/R) and j = (-Dz/R,Dx/R). You now want to find the maximum and minimum Z of this function (set of points), which again is defined to be x*i + f(x)*j. This boils down to finding the maximum of x*DZ/R + f(x)*Dx/R. Take the derivative on pen and paper, and find the zeroes (if you can't find the zeroes on paper, then use Newton-Raphson iteration to numerically find them in your program). Plug those zeroes back into the original equation, and you have the maximum Z. Finding the minimum Z involves the same process, only invert j and repeat (finding the local minimum instead). Note that if the projected direction vector is zero (because it's parallel to the Y axis), then you'd need to project to the YZ axis instead. The process is the same though.

Disclaimer: It's about 4 AM right now, so it's possible my thought process is off, but everything seems right at the moment.
Thanks, that make sense. Just a few things.
Quote:Original post by Zipster
This boils down to finding the maximum of x*DZ/R + f(x)*Dx/R.

I don't realy follow you here, why does one of coordinates on the axes fall of?
When I derivate should DZ, DX and R be considered as constants?
Quote:Original post by 51mon
I don't realy follow you here, why does one of coordinates on the axes fall of?
When I derivate should DZ, DX and R be considered as constants?

When you project the direction vector onto the XZ plane, it might not be unit length, however the basis vectors need to be. If the direction vector were unit length, then it would be (cos(θ),sin(θ)), where θ is the angle it makes with the X-axis. Instead of finding the angle and taking the cosine and sine, we use the other definitions of those functions, adjacent/hypotenuse and opposite/hypotenuse. R is just that hypotenuse.

And you are correct about differentiating with respect to x. Everything else is a constant.

This topic is closed to new replies.

Advertisement