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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:57:38+00:00 2026-05-27T08:57:38+00:00

I’m working on a project with 3D based objects and manipulating them via my

  • 0

I’m working on a project with 3D based objects and manipulating them via my program. I currently have a textbox that allows me to put a heading in degrees and a button that will calculate the required values to make my main object change its heading. This is the code for that function:

    private void btnSetHeading_Click(object sender, EventArgs e)
    {
        if (this.textBoxHeading.Text.Length == 0)
            return;

        float heading = (float)0;
        try
        {
            heading = float.Parse(this.textBoxHeading.Text);
        }
        catch (FormatException ex)
        {
            MessageBox.Show(ex.Message);
            return;
        }

        if (heading < (float)0 || heading > (float)360)
        {
            MessageBox.Show("Invalid heading parameter. Acceptable range: 0 - 360");
            return;
        }

        float tempCosine = (float)Math.Cos(((heading * Math.PI) / (float)360.0));
        float tempSine = -((float)Math.Sin(((heading * Math.PI) / (float)360.0)));
        try
        {
            ProgramInterop.CreateInstance.SetHeading(tempCosine, tempSine);
        }
        catch (Exception ex)
        {
            MessageBox.Show("Caught: " + ex.Message);

        }
    }

If I supply 90 as the heading to face, the results are tempCosine=0.7071068 and tempSine=-0.7071068, which then makes my main object face 90 degrees or due east.

The program requires the heading to be given in two seperate values(tempCosine and tempSine) which I’m not familiar with geometry enough to understand why I would multiply by 360 instead of 180 but this is how its required to work.

Now for the next part of my project involves making my main object face another object given both of their (x,y) coordinates. If for example my main object is at (9112.94, 22088.74) and the new object I want to face is at (9127.04, 22088.88), it would require almost exactly 90 degrees heading to make it face the new object.

How can I calculate the tempCosine and tempSine from those two coordinates?

  • 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-27T08:57:39+00:00Added an answer on May 27, 2026 at 8:57 am

    I was able to work out the answer using Dani’s suggestion to use Atan2(y, x). Thanks Dani.

    float x1 = 9112.94f;
    float y1 = 22088.74f;
    
    float x2 = 9127.04f;
    float y2 = 22088.88f;
    
    float angleRadians;
    
    float diffX = x2 - x1;
    float diffY = y2 - y1;
    
    float atan2Result = (float)Math.Atan2(diffX, diffY);
    angleRadians = atan2Result / 2;
    if (angleRadians < 0.0f)
        angleRadians += (float)Math.PI;
    
    float tempCosine = (float)Math.Cos(angleRadians);
    float tempSine = -((float)Math.Sin(angleRadians));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.