• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
asad_82

Angle between two 3D vectors expressed as phi and theta

18 posts in this topic

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
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
>[quote name='alvaro' timestamp='1304082576' post='4804413']
>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.
>[/quote]

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


0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
>[quote name='alvaro' timestamp='1304101848' post='4804514']
>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.
>[/quote]


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?

[size="2"][color="#1C2837"]Is this method of getting tangent correct?[/color][/size]
[color=#1C2837][size=2]
[/size][/color]
[color=#1C2837][size=2]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

[/size][/color]
[color=#1C2837][size=2]V = normalize(V')
W = N x V[/size][/color]
[color=#1C2837][size=2]
[/size][/color]
[color=#1C2837][size=2]Asad[/size][/color]
[color=#1C2837][size=2]
[/size][/color]
[color=#1C2837][size=2]
[/size][/color]
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[quote name='Asad' timestamp='1304136271' post='4804646']
>[quote name='alvaro' timestamp='1304101848' post='4804514']
>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.
>[/quote]


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?[/quote]
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).

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.

[quote]And how will I get the desired angles after that?[/quote]
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.

[size="2"][color="#1C2837"][quote]Is this method of getting tangent correct?[/color][/size]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]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

[/size][/color]
[color="#1C2837"][size="2"]V = normalize(V')
W = N x V[/size][/color]
[color="#1C2837"][size="2"][/quote][/size][/color]
[color="#1C2837"][size="2"]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.[/size][/color]
[size="2"][color="#1C2837"]
[/color][/size]
[size="2"][color="#1C2837"]As wildbunny just said, you should just tell us what you are trying to achieve.[/color][/size]
[size="2"][color="#1C2837"]
[/color][/size]
[size="2"][color="#1C2837"]
[/color][/size]
0

Share this post


Link to post
Share on other sites
[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 ([url="http://www.merl.com/brdf/"]http://www.merl.com/brdf/[/url]).
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
0

Share this post


Link to post
Share on other sites
[quote name='alvaro' timestamp='1304167149' post='4804736']
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).[/quote]

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?)

[quote name='alvaro' timestamp='1304167149' post='4804736']
[color="#1C2837"][size="2"]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.[/quote]

This is familiar to me if you replace "1D foliation" with "vector field;" then this is the version of the Hairy Ball Theorem [/size][/color]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?).
0

Share this post


Link to post
Share on other sites
[quote name='Asad' timestamp='1304176154' post='4804763']
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.
[/quote]

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?

[url="http://www.cs.princeton.edu/courses/archive/fall06/cos526/tmp/wynn.pdf"]http://www.cs.princeton.edu/courses/archive/fall06/cos526/tmp/wynn.pdf[/url]

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.

0

Share this post


Link to post
Share on other sites
[quote name='wildbunny' timestamp='1304184529' post='4804783']

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)

[/quote]



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.
0

Share this post


Link to post
Share on other sites
[quote name='Asad' timestamp='1304186010' post='4804787']
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.
[/quote]

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.
0

Share this post


Link to post
Share on other sites
[quote name='wildbunny' timestamp='1304187666' post='4804797']

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?

[/quote]

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.
0

Share this post


Link to post
Share on other sites
[quote name='Asad' timestamp='1304190356' post='4804814']
[quote name='wildbunny' timestamp='1304187666' post='4804797']
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?

[/quote]

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.
[/quote]

Ok, so what are IN and VIEW?

:)
0

Share this post


Link to post
Share on other sites
[quote name='wildbunny' timestamp='1304191626' post='4804816']

Ok, so what are IN and VIEW?

[/quote]

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.
0

Share this post


Link to post
Share on other sites
[quote name='Asad' timestamp='1304219141' post='4804921']
[quote name='wildbunny' timestamp='1304191626' post='4804816']
Ok, so what are IN and VIEW?

[/quote]

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.
[/quote]

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...

[url="http://people.csail.mit.edu/wojciech/BRDFDatabase/code/BRDFRead.cpp"]You must have seen this example code[/url]

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.
0

Share this post


Link to post
Share on other sites
[quote name='wildbunny' timestamp='1304247605' post='4805009']


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.
[/quote]

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
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0