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.
Tried googling it, but I can't even remember the proper name of the problem
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