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 6818435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:10:41+00:00 2026-05-26T21:10:41+00:00

for a school project I need to find theta and phi for a spherical

  • 0

for a school project I need to find theta and phi for a spherical texture map. A lot of the actual OpenGL for texturing is already completed (comes with the starter code). The starter code provides the function and comments below. The code is what I have done so far (besides the initialization for x and z, which was given) :

Vec3f sphere::getTextureCoords(Vec3f eye, Vec3f dir)
{
    // find the normal (getNormal)
    Vec3f n = this->getNormal(eye, dir);

    // use these to find spherical coordinates
    Vec3f x(1, 0, 0);
    Vec3f z(0, 0, 1);

    // phi is the angle down from z
    // theta is the angle from x curving toward y

    // find phi using the normal and z
    float phi = acos(n.Dot3(z));

    // find the x-y projection of the normal
    Vec3f proj(n.x(), n.y(), 0);

    // find theta using the x-y projection and x
    float theta = acos(proj.Dot3(x));

    // if x-y projection is in quadrant 3 or 4, then theta = 2PI - theta
    if (proj.y() < 0)
        theta = TWOPI - theta;

    Vec3f coords;
    coords.set(theta / TWOPI, phi / PI, 0);
    return coords;
}

Following the “instructions” in the comments, this is what I came up with. The texture map does not work though (no errors, the coordinates are just wrong). It is possible that the getNormal function is not working correctly but I believe the problem lies in my lack of understanding for spherical coordinates. Please let me know what you believe to be the issue, thanks!

  • 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-26T21:10:42+00:00Added an answer on May 26, 2026 at 9:10 pm

    Since proj is not normalized, you get a wrong result for theta.

    BTW, your naming of theta and phi is unconventional (it confused me at first). Usually the angle from z is called theta and the angle in the x-y-plane is called phi.

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

Sidebar

Related Questions

For a school project I need to create a program and it'd be nice
For a school project i need to write or use a online programming editor.
For a school project, I need to create a way to create personnalized queries
I'm currently building a console app for a school project and I really need
I need to build a small database for a school project and I'd like
First of all, I'll admit this is a school project, so I need more
For a project at school I need to have to absolute position of the
I need to write a Linux shell for a school project. We can use
I need to develop a Iphone 2D app for school project. I don't have
I have this school project I'm making, where I need to make my code

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.