# Working out the area of a spline loop, do I need to use shoelace formula and 2D projection?

**URL:** <https://forums.unrealengine.com/t/working-out-the-area-of-a-spline-loop-do-i-need-to-use-shoelace-formula-and-2d-projection/2469943>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, Blueprint, question, vector-math\
**Created:** [April 22, 2025, 2:55pm UTC](https://forums.unrealengine.com/t/working-out-the-area-of-a-spline-loop-do-i-need-to-use-shoelace-formula-and-2d-projection/2469943 "2025-04-22T14:55:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anthony\_Attwood](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anthony\_Attwood](https://forums.unrealengine.com/u/Anthony_Attwood)\
**Post date:** [April 22, 2025, 2:55pm UTC](https://forums.unrealengine.com/t/working-out-the-area-of-a-spline-loop-do-i-need-to-use-shoelace-formula-and-2d-projection/2469943/1 "2025-04-22T14:55:36Z")

</div>

Quick question, I’m trying to work out the area of a closed spline loop in 3D space. I’m coming across all kinds of complex methods for working out areas of n-sided polygons in 3D space and using the shoelace method. Is this really necessary? I thought I could simply calculate the area from the lengths of each spline segment?

I found this:

> **[Calculate Area posted by anonymous | blueprintUE | PasteBin For Unreal Engine](https://blueprintue.com/blueprint/hvqr0e39/)**
>
> No description provided

Does it matter whether it’s a flat spline on a 2D plane or spline oriented in any direction in 3D space?

---

<div class="post-metadata">

**Author:** ![SupportiveEntity](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SupportiveEntity](https://forums.unrealengine.com/u/SupportiveEntity)\
**Post date:** [April 23, 2025, 6:44am UTC](https://forums.unrealengine.com/t/working-out-the-area-of-a-spline-loop-do-i-need-to-use-shoelace-formula-and-2d-projection/2469943/2 "2025-04-23T06:44:43Z")

</div>

Hey there @Anthony_Attwood! That BP is a pretty good setup for the Shoelace method, and if you need the data as a 2D projection, that’s perfect. However if the shape is more than just an XY plane, this gets more complicated.

---

<div class="post-metadata">

**Author:** ![Anthony\_Attwood](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anthony\_Attwood](https://forums.unrealengine.com/u/Anthony_Attwood)\
**Post date:** [April 23, 2025, 1:18pm UTC](https://forums.unrealengine.com/t/working-out-the-area-of-a-spline-loop-do-i-need-to-use-shoelace-formula-and-2d-projection/2469943/3 "2025-04-23T13:18:52Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/4/5/4457dc8d76c322d6e3824a3b3b3368b87e249c99.jpeg)

I’m a bit noob when it comes to maths so I made a shape and used the blueprint above for the area calculation. The area is in the middle there. Is this the correct answer?

If not I think maybe it’s inaccurate.

The numbers are:

278.847 (left)

230.308 (right)

361.694 (base)

---

<div class="post-metadata">

**Author:** ![SupportiveEntity](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SupportiveEntity](https://forums.unrealengine.com/u/SupportiveEntity)\
**Post date:** [April 24, 2025, 8:13am UTC](https://forums.unrealengine.com/t/working-out-the-area-of-a-spline-loop-do-i-need-to-use-shoelace-formula-and-2d-projection/2469943/4 "2025-04-24T08:13:44Z")

</div>

That’s a good test since triangles are straightforward, it’s definitely wrong somehow. Doing the math in BP is less than ideal for me.

Is your project setup for C++? If so, you could use this, it’s partially ripped from an old VR magic gesture plugin that was never finished, but I tested it and it mostly works with some low inaccuracy but the formula seems correct so give it a try. If you don’t have your C++ project setup, please back your project up before doing so, it’s very possible to have problems doing so. I’m not working from my rig with source installed so I couldn’t bundle it into a plugin.

Once you get it working with the project, go into the spline BP and use this node it generates.

Here’s the CPP file:

```auto

#include "SplineAreaLibrary.h"
#include "Math/Vector.h" 
#include "Math/Vector2D.h" 
#include "Math/UnrealMathUtility.h" 

float USplineAreaLibrary::CalculateProjectedSplineArea2D(const USplineComponent* SplineComponent, EPlaneProjection ProjectionPlane, int32 NumSamples)
{
	//Warnings if messing up 
	if (!SplineComponent)
	{
		UE_LOG(LogTemp, Warning, TEXT("CalculateProjectedSplineArea2D: Invalid SplineComponent provided."));
		return 0.0f;
	}

	if (NumSamples < 3)
	{
		UE_LOG(LogTemp, Warning, TEXT("CalculateProjectedSplineArea2D: Need at least 3 samples for area calculation. Provided: %d"), NumSamples);
		return 0.0f;
	}

	const float SplineLength = SplineComponent->GetSplineLength();
	if (SplineLength <= 0.0f)
	{
		UE_LOG(LogTemp, Warning, TEXT("CalculateProjectedSplineArea2D: Spline length is zero or negative."));
		return 0.0f;
	}

	
	TArray<FVector2D> ProjectedPoints;
	ProjectedPoints.Reserve(NumSamples); 

	for (int32 i = 0; i < NumSamples; ++i)
	{
		const float Distance = (SplineLength / static_cast<float>(NumSamples)) * static_cast<float>(i);
		const FVector WorldLocation = SplineComponent->GetWorldLocationAtDistanceAlongSpline(Distance);

		
		FVector2D Point2D;
		switch (ProjectionPlane)
		{
		case EPlaneProjection::XZ:
			Point2D = FVector2D(WorldLocation.X, WorldLocation.Z);
			break;
		case EPlaneProjection::YZ:
			Point2D = FVector2D(WorldLocation.Y, WorldLocation.Z);
			break;
		case EPlaneProjection::XY:
		default: 
			Point2D = FVector2D(WorldLocation.X, WorldLocation.Y);
			break;
		}
		ProjectedPoints.Add(Point2D);
	}

	// Shoelace forumula. Inaccurate or just floating point problems?
	float ShoelaceSum = 0.0f;
	const int32 NumPoints = ProjectedPoints.Num();

	for (int32 i = 0; i < NumPoints; ++i)
	{
		const FVector2D& CurrentPoint = ProjectedPoints[i];
		const FVector2D& NextPoint = ProjectedPoints[(i + 1) % NumPoints];

		ShoelaceSum += (CurrentPoint.X * NextPoint.Y) - (CurrentPoint.Y * NextPoint.X);
	}

	
	const float Area = 0.5f * FMath::Abs(ShoelaceSum);

	return Area;
}

```

and here’s the header:

```auto

#include "SplineAreaLibrary.h"
#include "Math/Vector.h" 
#include "Math/Vector2D.h" 
#include "Math/UnrealMathUtility.h" 

float USplineAreaLibrary::CalculateProjectedSplineArea2D(const USplineComponent* SplineComponent, EPlaneProjection ProjectionPlane, int32 NumSamples)
{
	//Warnings if messing up 
	if (!SplineComponent)
	{
		UE_LOG(LogTemp, Warning, TEXT("CalculateProjectedSplineArea2D: Invalid SplineComponent provided."));
		return 0.0f;
	}

	if (NumSamples < 3)
	{
		UE_LOG(LogTemp, Warning, TEXT("CalculateProjectedSplineArea2D: Need at least 3 samples for area calculation. Provided: %d"), NumSamples);
		return 0.0f;
	}

	const float SplineLength = SplineComponent->GetSplineLength();
	if (SplineLength <= 0.0f)
	{
		UE_LOG(LogTemp, Warning, TEXT("CalculateProjectedSplineArea2D: Spline length is zero or negative."));
		return 0.0f;
	}

	
	TArray<FVector2D> ProjectedPoints;
	ProjectedPoints.Reserve(NumSamples); 

	for (int32 i = 0; i < NumSamples; ++i)
	{
		const float Distance = (SplineLength / static_cast<float>(NumSamples)) * static_cast<float>(i);
		const FVector WorldLocation = SplineComponent->GetWorldLocationAtDistanceAlongSpline(Distance);

		
		FVector2D Point2D;
		switch (ProjectionPlane)
		{
		case EPlaneProjection::XZ:
			Point2D = FVector2D(WorldLocation.X, WorldLocation.Z);
			break;
		case EPlaneProjection::YZ:
			Point2D = FVector2D(WorldLocation.Y, WorldLocation.Z);
			break;
		case EPlaneProjection::XY:
		default: 
			Point2D = FVector2D(WorldLocation.X, WorldLocation.Y);
			break;
		}
		ProjectedPoints.Add(Point2D);
	}

	// Shoelace forumula. Inaccurate or just floating point problems?
	float ShoelaceSum = 0.0f;
	const int32 NumPoints = ProjectedPoints.Num();

	for (int32 i = 0; i < NumPoints; ++i)
	{
		const FVector2D& CurrentPoint = ProjectedPoints[i];
		const FVector2D& NextPoint = ProjectedPoints[(i + 1) % NumPoints];

		ShoelaceSum += (CurrentPoint.X * NextPoint.Y) - (CurrentPoint.Y * NextPoint.X);
	}

	
	const float Area = 0.5f * FMath::Abs(ShoelaceSum);

	return Area;
}

```

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/c/e/9ceac14ead1c76dc4e4422b982f6b306a12b5d31.png)

---

<div class="post-metadata">

**Author:** ![Anthony\_Attwood](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anthony\_Attwood](https://forums.unrealengine.com/u/Anthony_Attwood)\
**Post date:** [April 24, 2025, 6:26pm UTC](https://forums.unrealengine.com/t/working-out-the-area-of-a-spline-loop-do-i-need-to-use-shoelace-formula-and-2d-projection/2469943/5 "2025-04-24T18:26:38Z")

</div>

Wooah this is incredible! I’ll back the project up and set it up for C++ and give this a try. Thank you so much for this. I’ll give an update as soon as possible.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [May 24, 2025, 6:26pm UTC](https://forums.unrealengine.com/t/working-out-the-area-of-a-spline-loop-do-i-need-to-use-shoelace-formula-and-2d-projection/2469943/6 "2025-05-24T18:26:51Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
