Teacher said I would need this some day, I thought she was lying :)

MstrGareth

Active Member
Ok, stupid math problem if anyone is able to assist. One of those things we all learned but only a few remember.


Trying to construct a function that will return a new location (xyz) when given the heading difference and the distance from the original location. This is what I was able to recall, but my math is wrong somewhere.

Code:
        protected Loc CalculateReferenceLoc(Loc originatingLoc, float originatingHeading, float headingOffset, float zAngle, float meterDistance)
        {
            float distance = meterDistance * 100;
            Loc NewLoc = new Loc();
            float NewHeading = originatingHeading + headingOffset;

            if (NewHeading > 360) NewHeading = NewHeading - 360;
            if (NewHeading < 0) NewHeading = NewHeading + 360;

            NewLoc.y = (float)(originatingLoc.y + ((distance * Math.Cos(zAngle / 128 * 90)) * Math.Cos(90 - (90 - NewHeading))));
            NewLoc.x = (float)(originatingLoc.x - ((distance * Math.Cos(zAngle / 128 * 90)) * Math.Sin(90 - (90 - NewHeading))));
            NewLoc.z = (float)(originatingLoc.z + (distance * Math.Sin(zAngle / 128 * 90)));

            //cBase.ISOutput("Loc: " + newLoc.ToString());
            return NewLoc;
        }

Tried googling it, but I can't even remember the proper name of the problem :(
 

Valerian

ISX Specialist
ok, well first of all, I'd suggest you use the KISS method. that whole original heading and heading offset thing is a bit clunky, throw it into a separate function or calculate the "new" heading before calling this func so it doesn't seem as confusing...

you said your math is wrong somewhere. In what way? what bad output are you getting from that function? try passing it headings/angles that move exactly along one plane at a time, an exact distance (10, 100, whatever) and see which plane(s) is(are) messing up, in which way, etc.
 

MstrGareth

Active Member
Actually I have to heading stuff in another function I call from inside this one, but added the snippet just incase it was needed for clarification :)

I m not looking to "figure out" what is wrong with the math since the re-inventing the wheel would take a long time in this case. Luckily its a commonly used formula in advanced math classes so I am just hoping someone remembers it off hand an can jot it down.

Thanks though.
 
Top Bottom