Problem with ActorToECEF matrix

Hello!

I noticed that I am receiving strange results with FMatrix GetActorToEarthCenteredEarthFixedMatrix().

I have a pawn which has a UCesiumGlobeAnchorComponent* GeoAwareComponent.

Here is the problem:
I get current ActorToECEF matrix, current UE location (AActor::GetActorLocation()), and try to apply retrieved ActorToECEF matrix on a vector containing current UE location:


	FMatrix Unreal2ECEF = GeoAwareComponent->GetActorToEarthCenteredEarthFixedMatrix();
	FVector CurrentUE = GetActorLocation();
	FVector CurrentECEF = Unreal2ECEF.TransformVector(CurrentUE);

To check this calculated ECEF current location I also logged:

  • current lon/lat/height calculated from TransformUnrealPositionToLongitudeLatitudeHeight method of CesiumGeoreference (from FVector CurrentUE)
  • current lon/lat/height
  • current ECEF position by converting lon/lat/height with LongitudeLatitudeHeightToEllipsoidCenteredEllipsoidFixed method of UCesiumEllipsoid

Here is the whole code:


	FMatrix Unreal2ECEF = GeoAwareComponent->GetActorToEarthCenteredEarthFixedMatrix();
	FVector CurrentUE = GetActorLocation();
	FVector CurrentECEF = Unreal2ECEF.TransformVector(CurrentUE);

	ACesiumGeoreference* Georeference = ACesiumGeoreference::GetDefaultGeoreference(GetWorld());

	UE_LOG(LogTemp, Log, TEXT("Current Geodetic from UE's coordinates: %s"),
		*Georeference->TransformUnrealPositionToLongitudeLatitudeHeight(CurrentUE).ToString());

	UE_LOG(LogTemp, Log, TEXT("Current LonLatHeight: %s"), *LonLatHeight.ToString());

	UE_LOG(LogTemp, Log, TEXT("Calculated ECEF: %s"), *CurrentECEF.ToString());

	UE_LOG(LogTemp, Log, TEXT("Current ECEF from Geodetic: %s"),
		*GeoAwareComponent->GetEllipsoid()->LongitudeLatitudeHeightToEllipsoidCenteredEllipsoidFixed(LonLatHeight).ToString());

And here is the output:

[2025.03.03-10.56.47:944][389]LogTemp: Current Geodetic from UE’s coordinates: X=45.000 Y=45.000 Z=112.641
[2025.03.03-10.56.47:944][389]LogTemp: Current LonLatHeight: X=45.000 Y=45.000 Z=112.641
[2025.03.03-10.56.47:944][389]LogTemp: Calculated ECEF: X=-3185911.535 Y=696531.304 Z=5464112.757
[2025.03.03-10.56.47:944][389]LogTemp: Current ECEF from Geodetic: X=3194475.465 Y=3194475.465 Z=4487428.058

As you can see calculated ECEF position by Unreal2ECEF matrix (using GetActorToEarthCenteredEarthFixedMatrix method) really differs from actual ECEF position.

What is the problem? Am I doing the transformation wrong?

Georeference was set to true origin.

p.s. I also tried with lat/lon/h origin: geoference was set to lat/lon/height at { 0.0, 0.0, 0.0 } and got this completely different result:

[2025.03.03-11.05.45:117][714]LogTemp: Current Geodetic from UE’s coordinates: X=45.002 Y=45.000 Z=121.122
[2025.03.03-11.05.45:117][714]LogTemp: Current LonLatHeight: X=45.002 Y=45.000 Z=121.122
[2025.03.03-11.05.45:117][714]LogTemp: Calculated ECEF: X=4487411.103 Y=880092.576 Z=4431144.957
[2025.03.03-11.05.45:117][714]LogTemp: Current ECEF from Geodetic: X=3194390.926 Y=3194600.943 Z=4487411.103

Hi @sandwitch,
The first thing that jumps out at me is that you’re calling Unreal2ECEF.TransformVector. You need to use TransformPosition because, well… you’re transforming a position!