Started by Apr 29 2011 06:39 AM

,
18 replies to this topic

Posted 29 April 2011 - 06:39 AM

I am interested in finding angle between two 3D vectors A = [a1, a2, z3] and N = [n1 n2 n3]

Typically the angle can be found as: angle = acos(A . N / (|A| |N|) )

But I am interested in the representation of this angle in spherical coordinates i.e. I want to know theta and phi angle separately ...... spherical coordinates of the angle found above.

The vector N is the normal vector and represents the normal at each point on a 3D sphere found as:

[x y z] = sphere

q = sqrt( x^2 + y^2 + z^2)

Nx = x / q

Ny = y / q

Nz = z / q

N = [Nx Ny Nz] ..... lets say for one point on the 3D sphere for clarity

And the vector A is the light vector whose angle should be found w.r.t to the normal and expressed as theta and phi (spherical coordinates) not just one angle value in 3D.

I am using matlab for this stuff so I am dealing with points on the sphere not some kind of meshes.

I would be thankful if anyone on the group can tell me what needs to be done.

Looking for feedback.....

Asad

Typically the angle can be found as: angle = acos(A . N / (|A| |N|) )

But I am interested in the representation of this angle in spherical coordinates i.e. I want to know theta and phi angle separately ...... spherical coordinates of the angle found above.

The vector N is the normal vector and represents the normal at each point on a 3D sphere found as:

[x y z] = sphere

q = sqrt( x^2 + y^2 + z^2)

Nx = x / q

Ny = y / q

Nz = z / q

N = [Nx Ny Nz] ..... lets say for one point on the 3D sphere for clarity

And the vector A is the light vector whose angle should be found w.r.t to the normal and expressed as theta and phi (spherical coordinates) not just one angle value in 3D.

I am using matlab for this stuff so I am dealing with points on the sphere not some kind of meshes.

I would be thankful if anyone on the group can tell me what needs to be done.

Looking for feedback.....

Asad

Posted 29 April 2011 - 07:09 AM

An angle is only what you described (the arc-cosine of the normalized inner product). It seems to me that what you want to do is something like applying a rotation that will make the normal be (0,0,1) and see where the light vector ends up. However, that's still ill specified: The angle between the normal and the light is well defined, but the other one requires having a full reference frame, not just a normal vector.

Posted 29 April 2011 - 07:26 AM

If my understanding of your problem is correct then first you need to know what axis theta and phi are rotating about. You want to look down each axis in turn (and thus make the problem into a 2d one), work out that angle. Then I guess you will need to rotate both the next axis AND the original vector around the first axis and by the angle you worked out. Now you look down your new, rotated axis and flattern the vectors so they're 2d on a plane perpendicular to the axis your now looking down. Now its in 2d you can work out the next angle.

Hopefully that makes sense but I have my doubts.

Hopefully that makes sense but I have my doubts.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

Posted 29 April 2011 - 09:09 AM

>

Thanks for the reply

But I didnt understand what you mean by the reference frame.

The normal vector of a point on the sphere is the reference about which I have to measure the theta angle and the projection of the normal on the surface that you can call a tangent is the other vector about which the Phi angle needs to be measured.

What I want to do is to fetch a value of BRDF (Bidirectional reflectance distribution function) for a given theta_In and phi_In and theta_View and Phi_view for rendering a sphere.

I have one light source and its direction and the viewer direction.

For simplicity lets just find the local angle of the light vector with the normal vector of a point on the sphere.

This evaluation should give me angle in the form of theta_In and phi_In for indexing in the BRDF for fetching data.

I am working with actual BRDF data and just want to render a sphere using that.

The figure of angles I need to measure is also attached for clarity.

Regards

Asad

>An angle is only what you described (the arc-cosine of the normalized inner product). It seems to me that what you want to do is something like applying a rotation that will make the normal be (0,0,1) and see where >the light vector ends up. However, that's still ill specified: The angle between the normal and the light is well defined, but the other one requires having a full reference frame, not just a normal vector.

>

Thanks for the reply

But I didnt understand what you mean by the reference frame.

The normal vector of a point on the sphere is the reference about which I have to measure the theta angle and the projection of the normal on the surface that you can call a tangent is the other vector about which the Phi angle needs to be measured.

What I want to do is to fetch a value of BRDF (Bidirectional reflectance distribution function) for a given theta_In and phi_In and theta_View and Phi_view for rendering a sphere.

I have one light source and its direction and the viewer direction.

For simplicity lets just find the local angle of the light vector with the normal vector of a point on the sphere.

This evaluation should give me angle in the form of theta_In and phi_In for indexing in the BRDF for fetching data.

I am working with actual BRDF data and just want to render a sphere using that.

The figure of angles I need to measure is also attached for clarity.

Regards

Asad

Posted 29 April 2011 - 12:30 PM

The foot of the image you just posted explains the problem I raised: You need a tangent vector t with respect to which the phi angles will be measured.

Posted 29 April 2011 - 10:04 PM

>

Yes thats true I need a tangent vector.

Can you please tell me how to get the tangent for each point on the sphere given the normal vectors at each point as described earlier?

And how will I get the desired angles after that?

Is this method of getting tangent correct?

given Normal = N = (n1,n2,n3)

V' = ( 0,-n3, y ) if n1 is the smallest

( -n3, 0, n1 ) if n2 is the smallest

( -n2, n1, 0 ) if n3 is the smallest

V = normalize(V')

W = N x V

Asad

>The foot of the image you just posted explains the problem I raised: You need a tangent vector t with respect to which the phi angles will be measured.

>

Yes thats true I need a tangent vector.

Can you please tell me how to get the tangent for each point on the sphere given the normal vectors at each point as described earlier?

And how will I get the desired angles after that?

Is this method of getting tangent correct?

given Normal = N = (n1,n2,n3)

V' = ( 0,-n3, y ) if n1 is the smallest

( -n3, 0, n1 ) if n2 is the smallest

( -n2, n1, 0 ) if n3 is the smallest

V = normalize(V')

W = N x V

Asad

Posted 30 April 2011 - 04:06 AM

This all sounds very overcomplicated - what is the end result of what you're trying to achieve?

BDRF look-up? What lighting effect is it?

Cheers, Paul.

BDRF look-up? What lighting effect is it?

Cheers, Paul.

Posted 30 April 2011 - 06:39 AM

No, I can't. There are many many ways of assigning a tangent for each point on the sphere (in Math such an assignment is called a foliation).>

>The foot of the image you just posted explains the problem I raised: You need a tangent vector t with respect to which the phi angles will be measured.

>

Yes thats true I need a tangent vector.

Can you please tell me how to get the tangent for each point on the sphere given the normal vectors at each point as described earlier?

If your BRDF is isotropic, you don't really need to compute phi at all (only the difference between phi of the light vector and phi of the eye vector, which doesn't require a reference tangent vector). If your BRDF is anisotropic, which reference tangent vector you use matters, and then it's part of the description of the material.

You change coordinates so the surface is now tangent to z=0 and you can then ignore the z coordinate and compute angles in 2D.And how will I get the desired angles after that?

Is this method of getting tangent correct?

given Normal = N = (n1,n2,n3)

V' = ( 0,-n3, y ) if n1 is the smallest

( -n3, 0, n1 ) if n2 is the smallest

( -n2, n1, 0 ) if n3 is the smallest

V = normalize(V')

W = N x V

Assuming by "y" you mean "n2" in the case where n1 is the smallest, this does result in a selection of a tangent vector everywhere, but it has discontinuities, which would probably result in visual artifacts if you had an anisotropic BRDF. You can't find a way to assign a reference tangent vector so no discontinuities appear, since every continuous 1D foliation on the sphere has a singularity. This is a fundamental obstruction of reality, not an issue with your computation.

As wildbunny just said, you should just tell us what you are trying to achieve.

Posted 30 April 2011 - 09:09 AM

[quote name='alvaro' timestamp='1304167149' post='4804736']

Thanks for your reply Alvaro and Wildbunny. I am grateful that you followed the post.

I want to render a sphere using actual BRDF data from MERL (http://www.merl.com/brdf/).

I want to do it for a single light source.

To render the BRDF from MERL i need to index into the BRDF data. For that purpose I need to calculate local theta_IN, phi_IN and local theta_VIEW, phi_VIEW at each point on the sphere.

Although the MERL data is isotropic but still I want to have all the above four angles calculated.

Now the question is how to calculate theta and phi for light and view locally at each point on the sphere w.r.t to the normal at the point and the tangent / binormal?

I hope I have been very clear and precise of what I want to do.

Looking forward for some answers?

Asad

Thanks for your reply Alvaro and Wildbunny. I am grateful that you followed the post.

I want to render a sphere using actual BRDF data from MERL (http://www.merl.com/brdf/).

I want to do it for a single light source.

To render the BRDF from MERL i need to index into the BRDF data. For that purpose I need to calculate local theta_IN, phi_IN and local theta_VIEW, phi_VIEW at each point on the sphere.

Although the MERL data is isotropic but still I want to have all the above four angles calculated.

Now the question is how to calculate theta and phi for light and view locally at each point on the sphere w.r.t to the normal at the point and the tangent / binormal?

I hope I have been very clear and precise of what I want to do.

Looking forward for some answers?

Asad

Posted 30 April 2011 - 09:41 AM

No, I can't. There are many many ways of assigning a tangent for each point on the sphere (in Math such an assignment is called a foliation).

Why "foliation" and not just "vector field?"

(I see that you can "almost" go from one to the other and back -- you definitely can locally, with the leaves as integral curves of your vector field -- but I'm not sure they're isomorphic?)

You can't find a way to assign a reference tangent vector so no discontinuities appear, since every continuous 1D foliation on the sphere has a singularity.

This is familiar to me if you replace "1D foliation" with "vector field;" then this is the version of the Hairy Ball Theorem I know... I guess a "singularity" in the case of a 1d foliation would be a place where one of your leaves drops a dimension (Here your leaves are (the images of) curves, and, at the points corresponding to vanishing vector fields, these degenerate into points?).

Posted 30 April 2011 - 11:28 AM

To render the BRDF from MERL i need to index into the BRDF data. For that purpose I need to calculate local theta_IN, phi_IN and local theta_VIEW, phi_VIEW at each point on the sphere.

Although the MERL data is isotropic but still I want to have all the above four angles calculated.

Ok, so are you're just talking about converting the incoming light direction L and the view vector V into spherical coordinates?

I did a quick google and found this primer on BRDFs which describes a quick conversion between cartesian and spherical coordinates, but I presume you've already seen this?

http://www.cs.princeton.edu/courses/archive/fall06/cos526/tmp/wynn.pdf

x = cos(phi) * sin(theta)

y = sin(phi) * sin(theta)

z = cos(theta)

phi = atan (x/y)

theta = atan( sqrt(x^2 + y^2) / z^2)

Hope that helps!

Cheers, Paul.

Posted 30 April 2011 - 11:53 AM

x = cos(phi) * sin(theta)

y = sin(phi) * sin(theta)

z = cos(theta)

phi = atan (x/y)

theta = atan( sqrt(x^2 + y^2) / z^2)

Thanks for your attempt Wildbunny but I think you missed a point here.

The conversions you described are typical coordinate conversions from Cartesian to spherical and vice versa.

But what I need is a angle between two 3D vectors one of which is a normal vector N and the other can be a Light vector or a view vector.

This angle is simple to measure with acos stuff as I described in my first post.

But I need the two components of this angle i.e. theta and phi.

For that a coordinate needs to be built comprising of Normal vector, Tangent Vector and Binormal w.r.t to which the angles will be measured.

And then we can get the phi angle.

That where the problem is .... how to do that for each point on a sphere given normal for each point.

Posted 30 April 2011 - 12:21 PM

But what I need is a angle between two 3D vectors one of which is a normal vector N and the other can be a Light vector or a view vector.

This angle is simple to measure with acos stuff as I described in my first post.

Can you tell us why you need this angle in the first place?

I'm still not totally sure what you're attempting to do - is it not just getting light direction and view vector in spherical coordinates?

Cheers, Paul.

Posted 30 April 2011 - 01:05 PM

Can you tell us why you need this angle in the first place?

I'm still not totally sure what you're attempting to do - is it not just getting light direction and view vector in spherical coordinates?

Well a BRDF is a 4D function at each point on a surface such as theta_IN phi_IN and theta_VIEW and phi_VIEW.

So in order to index into BRDF data such as that of MERL you need to calculate these angles with the normal and tangent at each point on the sphere to get the corresponding BRDF value.

I hope you got it now.

Many people who have been working with models such a phong, Blinn Phong and Lafortune can easily get it wrong. There the concept is all together different.

The one I want to do is the actual rendering of the material from acquired BRDF data.

Posted 30 April 2011 - 01:27 PM

Can you tell us why you need this angle in the first place?

I'm still not totally sure what you're attempting to do - is it not just getting light direction and view vector in spherical coordinates?

Well a BRDF is a 4D function at each point on a surface such as theta_IN phi_IN and theta_VIEW and phi_VIEW.

Ok, so what are IN and VIEW?

Posted 30 April 2011 - 09:05 PM

Ok, so what are IN and VIEW?

Well the IN direction is the light source direction calculated w.r.t to the surface normal and the VIEW direction is also w.r.t to the surface normal at a each point on the sphere.

Please see figure I posted of the arrangement in one of the earlier posts.

The concept is very simple I hope you are not lost any more.

Posted 01 May 2011 - 05:00 AM

Ok, so what are IN and VIEW?

Well the IN direction is the light source direction calculated w.r.t to the surface normal and the VIEW direction is also w.r.t to the surface normal at a each point on the sphere.

Please see figure I posted of the arrangement in one of the earlier posts.

The concept is very simple I hope you are not lost any more.

Looking at the example code that MERL provides for reading its BDRFs, it looks like the the required angles are not in tangent space as you seem to be implying, but rather in object space, accessed by what they call 'half vector difference' coordinates...

You must have seen this example code

They provide example code to map between 'standard coordinates' which appear to just be spherical coordinates, and their special coordinate system... I take it this is no good to you?

Cheers, Paul.

Posted 01 May 2011 - 11:33 AM

Looking at the example code that MERL provides for reading its BDRFs, it looks like the the required angles are not in tangent space as you seem to be implying, but rather in object space, accessed by what they call 'half vector difference' coordinates...

They provide example code to map between 'standard coordinates' which appear to just be spherical coordinates, and their special coordinate system... I take it this is no good to you?

Cheers, Paul.

Dear Paul

Thanks for it. Yes I have seen it earlier. This piece of code has to do with how the data is stored after re-parametrization from 4D to 3D.

It has nothing to do with how to display the data using local coordinate system at each point.

Asad

Posted 01 May 2011 - 12:08 PM

Well I think I have solved the issue and how I computed the four angles theta_IN phi_IN and theta_VIEW phi_VIEW locally for each point on the sphere is described below for others to validate and use as required:

I will describe it for one particular Normal vector and is valid as it is for all points on the sphere. The assumption is of a isotropic BRDF

All vectors are normalized before and during the computation.

L is light vector in Cartesian space

V is view vector in Cartesian space

N = [Nx Ny Nz] % normal vector

if abs(N(2)) ~= 1

TT = [0 1 0] % local tangent vector when surface normal is not in y direction

elseif abs(N(3)) ~= 1

TT = [0 0 1] % local tangent vector when surface normal is not in z direction

elseif abs(N(1)) ~= 1

TT = [1 0 0] % local tangent vector when surface normal is not in x direction

end

T = cross(TT,N) % get the tangent in local space

B = cross(N,T) % compute binormal which is orthogonal to both N and T

LP = L - dot(N,L) .* N % project L into the plane of surface to calculate phi_IN later

theta_IN = acos(dot(L,N) / norm(L)*norm(N)) % theta is the angle between the light and normal vector

phi_IN = atan2(dot(LP,B), dot(LP,T)) % phi is the angle computed from the projection of L onto the plane using binormal and tangent

VP = V - dot(N,V) .*N % project V into the plane of surface to calculate phi_VIEW later

theta_VIEW = acos(dot(V,N) / norm(V)*norm(N)) % theta is the angle between the view and normal vector

phi_VIEW = atan2(dot(VP,B), dot(VP,T)) % phi is the angle computed from the projection of V onto the plane using binormal and tangent

Theta should be in the range 0 - pi/2 and phi in the range 0 - 2*pi

Let me know if there is some mistake.

Cheers

Asad

I will describe it for one particular Normal vector and is valid as it is for all points on the sphere. The assumption is of a isotropic BRDF

All vectors are normalized before and during the computation.

L is light vector in Cartesian space

V is view vector in Cartesian space

N = [Nx Ny Nz] % normal vector

if abs(N(2)) ~= 1

TT = [0 1 0] % local tangent vector when surface normal is not in y direction

elseif abs(N(3)) ~= 1

TT = [0 0 1] % local tangent vector when surface normal is not in z direction

elseif abs(N(1)) ~= 1

TT = [1 0 0] % local tangent vector when surface normal is not in x direction

end

T = cross(TT,N) % get the tangent in local space

B = cross(N,T) % compute binormal which is orthogonal to both N and T

LP = L - dot(N,L) .* N % project L into the plane of surface to calculate phi_IN later

theta_IN = acos(dot(L,N) / norm(L)*norm(N)) % theta is the angle between the light and normal vector

phi_IN = atan2(dot(LP,B), dot(LP,T)) % phi is the angle computed from the projection of L onto the plane using binormal and tangent

VP = V - dot(N,V) .*N % project V into the plane of surface to calculate phi_VIEW later

theta_VIEW = acos(dot(V,N) / norm(V)*norm(N)) % theta is the angle between the view and normal vector

phi_VIEW = atan2(dot(VP,B), dot(VP,T)) % phi is the angle computed from the projection of V onto the plane using binormal and tangent

Theta should be in the range 0 - pi/2 and phi in the range 0 - 2*pi

Let me know if there is some mistake.

Cheers

Asad