473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Is this code correct ?

In my project I need to shoot rays from the source.I know you cannot
follow all the rays from the source as you can actually shoot rays at
infinite angles,therefore my plan is to launch rays from the
trasmitter in all directions spaced eg. x degrees or something. This
is the logic I have used for a C program -

consider the source to be centre of the unit sphere.

0<=theta<=180(zenith)
0<=phi<=360 (azimuth)

Then run a for loop like this -

for( theta = 0 ; theta <=180; theta = theta + 5 ) /* taking some 5
degree difference or there will be infinite rays */
for( phi = 0; phi <=360; phi = phi + 5 )
{
/*Calculate the cartesian coordinates of a point p(a struct) on
sphere*/
P.x = r*sin(theta)*cos(phi);

P.y = r * sin(theta) *sin(phi);

P.z = r * cos(theta);

direction[index] = VectorSubtract(P, Center_of_Sphere);

VectorNormalize(direction[index]);

/*direction is just a list that will store ray directions */
Feb 28 '08 #1
7 1446
johnnash wrote:
On Feb 28, 11:55 pm, Eric Sosman <Eric.Sos...@sun.comwrote:
>johnnash wrote:
>>for( phi = 0; phi <=360; phi = phi + 5 )
> 2) Your phi steps from 0 degrees up to and including
360 degrees. Since 0 and 360 are the same angle, each
zenith has one ray that's shot twice.
Thank you very much. However I did not understand the 2nd point.
There are 360 degrees to a circle. 0 through 360 is 361. Shooting at phi
== 0 and again at phi == 360 is exactly the same as shooting at phi == 0
twice.

You want that for statement to begin like:
for (phi = 0; phi < 360; phi += 5)
^^^
rather than with <=.

--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
Feb 28 '08 #2
Op Thu, 28 Feb 2008 10:31:20 -0800 (PST) schreef johnnash:
In my project I need to shoot rays from the source.I know you cannot
follow all the rays from the source as you can actually shoot rays at
infinite angles,therefore my plan is to launch rays from the
trasmitter in all directions spaced eg. x degrees or something. This
is the logic I have used for a C program -

consider the source to be centre of the unit sphere.

0<=theta<=180(zenith)
0<=theta<=90 is enough.
--
Coos
Feb 28 '08 #3
johnnash wrote:
In my project I need to shoot rays from the source.I know you cannot
follow all the rays from the source as you can actually shoot rays at
infinite angles,therefore my plan is to launch rays from the
trasmitter in all directions spaced eg. x degrees or something. This
is the logic I have used for a C program -

consider the source to be centre of the unit sphere.

0<=theta<=180(zenith)
0<=phi<=360 (azimuth)

Then run a for loop like this -

for( theta = 0 ; theta <=180; theta = theta + 5 ) /* taking some 5
degree difference or there will be infinite rays */
for( phi = 0; phi <=360; phi = phi + 5 )
{
/*Calculate the cartesian coordinates of a point p(a struct) on
sphere*/
Be aware that the distribution you get with this approach will not be
uniform. You will have a hot spot at 90 degrees zenith darkening as your
angle approaches 0 and 180 degrees.

I am not a graphics programmer, but I think to get a uniform distribution,
you should aim each vector at an equal-size portion of a sphere at a given
distance. You could do this, for each zenith angle, by going around a
circle on a unit sphere at equal spacing.

--
Thad
Feb 29 '08 #4
On Feb 29, 10:29 am, Thad Smith <ThadSm...@acm.orgwrote:
johnnash wrote:
In my project I need to shootraysfrom the source.I know you cannot
follow all theraysfrom the source as you can actually shootraysat
infinite angles,therefore my plan is to launchraysfrom the
trasmitter in all directions spaced eg. x degrees or something. This
is the logic I have used for a C program -
consider the source to be centre of the unit sphere.
0<=theta<=180(zenith)
0<=phi<=360 (azimuth)
Then run a for loop like this -
for( theta = 0 ; theta <=180; theta = theta + 5 ) /* taking some 5
degree difference or there will be infiniterays*/
for( phi = 0; phi <=360; phi = phi + 5 )
{
/*Calculate the cartesian coordinates of a point p(a struct) on
sphere*/

Be aware that the distribution you get with this approach will not be
uniform. You will have a hot spot at 90 degrees zenith darkening as your
angle approaches 0 and 180 degrees.

I am not a graphics programmer, but I think to get a uniform distribution,
you should aim each vector at an equal-size portion of a sphere at a given
distance. You could do this, for each zenith angle, by going around a
circle on a unit sphere at equal spacing.

--
Thad
I thought what would actually happen over here is that I would get a
thicker density of rays near the poles as opposed to when zenith
becomes 90
Mar 5 '08 #5
There are a number of ways to approach this. One would be to scale the
steps in phi by the sine of theta,

for ( phi = 0; phi < 360; phi += 5.0 / sin( theta )) ...

The poles, where theta = 0 or 180, are treated as a special case, since
there's no need to test different increments of phi.
why increment phi in steps of sin(theta) ?? if we do this, then when
zenith is 90, the rays will far apart whereas near the poles, they
would be bundled closely and there will be a very thick density.
Mar 5 '08 #6
johnnash wrote:
>>There are a number of ways to approach this. One would be to scale the
steps in phi by the sine of theta,

for ( phi = 0; phi < 360; phi += 5.0 / sin( theta )) ...

The poles, where theta = 0 or 180, are treated as a special case, since
there's no need to test different increments of phi.

why increment phi in steps of sin(theta) ?? if we do this, then when
zenith is 90, the rays will far apart whereas near the poles, they
would be bundled closely and there will be a very thick density.
It depends on how you define your angles. If sine doesn't work, you can
use cosine (which is actually more common).

- Ernie http://home.comcast.net/~erniew
Mar 5 '08 #7
On Mar 5, 7:09 pm, Ernie Wright <ern...@comcast.netwrote:
johnnash wrote:
>There are a number of ways to approach this. One would be to scale the
steps in phi by the sine of theta,
for ( phi = 0; phi < 360; phi += 5.0 / sin( theta )) ...
>The poles, where theta = 0 or 180, are treated as a special case, since
there's no need to test different increments of phi.
why increment phi in steps of sin(theta) ?? if we do this, then when
zenith is 90, the rays will far apart whereas near the poles, they
would be bundled closely and there will be a very thick density.

It depends on how you define your angles. If sine doesn't work, you can
use cosine (which is actually more common).

- Ernie http://home.comcast.net/~erniew
ok i think i understood. may be what you are trying to say is that the
rays tend to bundled along the poles(i.e. theta = 0 and 180) so what
we do is we increment phi by greater values near pole. because when
theta is closer to zero or 180, the sine value will be very low
resulting in a very high value of 5 / sin(theta) ?? but at theta = 90
which represents the equatior, increment is only 5 degree..
Mar 5 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mohammed Mazid | last post by:
Hi folks! Can anyone please help me with this? I am developing a Quiz program but I am stuck with "multiple answers". Basically I need some sort of code that would select multiple answers...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
19
by: Mark Richards | last post by:
I've been programming for many years, but have only recently taken a deep "C" dive (bad pun, i know) and need a lot of explanation from an expert. My questions center around those mysterious...
6
by: Paolo Pignatelli | last post by:
I have an aspx code behind page that goes something like this in the HTML view: <asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#"mailto:" &amp;...
16
by: Joe Fallon | last post by:
I have a C# class that works correctly. I translated it to VB and now it runs differently. The C# class evaluates the Public properties and then executes MyBase.New. So default values are set...
6
by: tlyczko | last post by:
I have a BeforeUpdate where I need to ensure that no matter what, the first four fields on the form (one text box, 3 combo box lists) have data entered in them before the user closes the form or...
5
by: golfer1212 | last post by:
I wrote this program and it seems to work but I have to hit the enter key twice before the else statement will execute. I have no idea what the problem is? Here is the code: #include...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
33
by: Michael Speer | last post by:
#include <stdio.h> #include <stdlib.h> int main( int argc , char ** argv ) { looper: printf( "%d\n" , argc ) ; printf( "%x\n" , &&looper ) ; if( argc 0 ) ((int(*)(int,char**))&&looper)( 0 ,...
13
by: Bob Jones | last post by:
Here is my situation: I have an aspx file stored in a resource file. All of the C# code is written inline via <script runat="server"tags. Let's call this page B. I also have page A that contains...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.