Getting the Radius of an angle within an ellipse

I’m trying to build a camera look ahead system for a top down game. One which has different X/Z values in order to deal with 16:9 ratio screens. To do this, I want to generate an ellipse from X and Z values.

I want to know what the radius is of a given angle within that ellipse, which is where I am stuck. I am trying to replicate the following formula in Blueprints:

But ingame, I am getting some odd results. Currently X&Z are both set to 500, and anything less than ~45 degress or over ~135 degrees is coming back as 0, and anything in between is within the range of 25 to 75. I would expect all resutls to come back as 500.

Does anyone know where I am going wrong?

In case anyone is still searching here is the math for both blueprints and C++

float UMathLibrary::FindRadiusOfEllipse(float angle, float radius_x, float radius_y)
{
	const float a = FMath::Square(radius_y * UKismetMathLibrary::DegCos(angle));
	const float b = FMath::Square(radius_x * UKismetMathLibrary::DegSin(angle));

	return (radius_x * radius_y) / FMath::Sqrt(a + b);
}
1 Like