Assuming the upper left corner is (0,0) and I\'m given an angle of 30 degrees, a starting point of (0,300), a line length of 600, how do I calculate the ending point of the
People are forgetting the complex
library in C++, which does polar to rectangular conversions for us.
complex getEndPoint(complex const &startPoint, double magnitude, double radians)
{
return startPoint + polar(magnitude, radians);
}
int main()
{
complex startingPoint(0.0, 300.0);
auto newPoint = getEndPoint(startingPoint, 600, 0.523598776);
cout << newPoint << endl;
}
I'd also be careful with your chosen terminology. When I see get
in a name, I think of it as retrieving an answer stored somewhere. In this example, we're computing something, and that could be false assurance given to a user of your code.