Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7690161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:19:56+00:00 2026-05-31T20:19:56+00:00

I have defined 2 points on the surface of a sphere using spherical coordinates.

  • 0

I have defined 2 points on the surface of a sphere using spherical coordinates.

// define end point positions
float theta_point_1 = (5/10.0)*M_PI;
float phi_point_1 = (5/10.0)*2*M_PI;
float x_point_1 = Radius * sin(theta_point_1) * cos(phi_point_1);
float y_point_1 = Radius * sin(theta_point_1) * sin(phi_point_1);
float z_point_1 = Radius * cos(theta_point_1);

float theta_point_2 = (7/10.0)*M_PI;
float phi_point_2 = (1/10.0)*2*M_PI;
float x_point_2 = Radius * sin(theta_point_2) * cos(phi_point_2);
float y_point_2 = Radius * sin(theta_point_2) * sin(phi_point_2);
float z_point_2 = Radius * cos(theta_point_2);


// draw end points
void end_points ()
{
    glColor3f (1.0, 1.0, 1.0);
    glPointSize(25.0);
    glBegin(GL_POINTS);
    glVertex3f(x_point_1,y_point_1,z_point_1);
    glVertex3f(x_point_2,y_point_2,z_point_2);
    glEnd();
}

To step between the two points, I do the following:

  1. find the difference between theta_points_1,2 and phi_points_1,2
  2. divide the differences by ‘n’ (yielding ‘s’)
  3. redraw ‘n’ times, while stepping up the theta and phi by ‘s’ each time

In the following, I’ve defined the differences between my theta and phi values, divided them, and then redraw them.

// begining spherical coords
float theta_point_1_value=5;
float phi_point_1_value=5;

// ending sperical coords
float theta_point_2_value=7;
float phi_point_2_value=1;

// dividing the difference evenly
float step_points=30;
float step_theta = 2/step_points;
float step_phi = 4/step_points;

// step between spherical coordinates
void stepping_points ()
{
    glColor3f (1.0, 0.0, 0.0); 
    for (int i = 1; i < step_points; i++)
    {
        float theta = (theta_point_1_value/10.0)*M_PI;
        float phi = (phi_point_1_value/10.0)*2*M_PI;
        float x = Radius * sin(theta) * cos(phi);
        float y = Radius * sin(theta) * sin(phi);
        float z = Radius * cos(theta);  
        glPushMatrix();         
        glTranslatef(x,y,z);
        glutSolidSphere (0.05,10,10);
        glPopMatrix(); 
    }  
    glEnd();
}

Now I understand, this displays 30 solid spheres at the same position. Because I have NOT included ‘step_theta’ or ‘step_phi’ in any of the redraws.

And that is the root of my question. How do I employ ‘step_theta’ and ‘step_phi’ in my redraws?

What I want to do is say something like this at the top of my ‘for’ loop:

    for (int i = 1; i < step_points; i++)
    {
        float theta_point_1_value = (theta_point_1_value+step_theta);
        float phi_point_1_value = (phi_point_1_value+step_phi);

        float theta = (theta_point_1_value/10.0)*M_PI;
        float phi = (phi_point_1_value/10.0)*2*M_PI;
        float x = Radius * sin(theta) * cos(phi);
        float y = Radius * sin(theta) * sin(phi);
        float z = Radius * cos(theta);  
        glPushMatrix();         
        glTranslatef(x,y,z);
        glutSolidSphere (0.05,10,10);
        glPopMatrix(); 
    } 

The above will redraw 30 solid spheres, but they don’t show between my defined end points. It’s pretty clear that either my math or syntax is screwy (or more than likely, both are).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:19:58+00:00Added an answer on May 31, 2026 at 8:19 pm

    Hint: What is the range of your loop variable, i? What do you want the range of your step_theta and step_phi to be?

    When you declare a variable inside the loop, it goes out of scope and is destructed after every iteration. As such, only the value of i changes between your loop iterations.

    Also: Consider using a vector/point class. (x_point_1, y_point_1) is not C++ :).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have the MapKit connect defined points using the Google Maps
I have a set S of points (2D : defined by x and y)
I have a 4 side convex Polygon defined by 4 points in 2D, and
I have a function defined like this: public static void ShowAbout(Point location, bool stripSystemAssemblies
is it possible to have links on the welcome page which point to defined
I have an implicit scalar field defined in 2D, for every point in 2D
I have two models, Category and Point . The associations are defined as: Category
When you define an extension-point in an Ant build file you can have it
OK, I have defined a PHP constant that points to a file on the
I have a mesh defined by 4 points in 3D space. I need an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.