# Get the highest slope along a spline

**URL:** <https://forums.unrealengine.com/t/get-the-highest-slope-along-a-spline/144266>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [May 23, 2020, 4:21pm UTC](https://forums.unrealengine.com/t/get-the-highest-slope-along-a-spline/144266 "2020-05-23T16:21:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detilium](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/detilium/32/985007_2.png) [@Detilium](https://forums.unrealengine.com/u/Detilium)\
**Post date:** [May 23, 2020, 4:21pm UTC](https://forums.unrealengine.com/t/get-the-highest-slope-along-a-spline/144266/1 "2020-05-23T16:21:37Z")

</div>

Hello.

I’m trying to implement conveyor lines that the player can construct during gameplay. I have a certain set of rules that the player must consider, when constructing the conveyor.  
One of these rules are the maximum slope allowed at any given distance along the spline.

However, I’m not sure how to calculate this.

I’ve looked into formulars to calculate the angle between two vectors, but I can’t seem to wrap my head around the maths 🙂

Hence this post. I appreciate all the help I can get 🙂

If you need further information to understand the issue, please don’t hesitate to ask. I’ll do my best to answer 🙂

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_82dfa2f11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_82dfa2f11](https://forums.unrealengine.com/u/anonymous_user_82dfa2f11)\
**Post date:** [May 24, 2020, 12:08am UTC](https://forums.unrealengine.com/t/get-the-highest-slope-along-a-spline/144266/2 "2020-05-24T00:08:36Z")

</div>

Step by step video for finding the angle between two 3D vectors written out: [How to Find the Angle Between Two 3D Vectors - YouTube](https://www.youtube.com/watch?v=QWIZXRjMspI) Also, when you say “slope allowed at any given distance along the spline” what do you mean? I’m imagining that you have conveyor segments that you’re connecting together, and their pitches may be set tilting upward/downwards, correct? And you have rules to make sure they’re set reasonably (say, between 45 and -45 degrees or something)?

---

<div class="post-metadata">

**Author:** ![Detilium](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/detilium/32/985007_2.png) [@Detilium](https://forums.unrealengine.com/u/Detilium)\
**Post date:** [May 24, 2020, 12:17am UTC](https://forums.unrealengine.com/t/get-the-highest-slope-along-a-spline/144266/3 "2020-05-24T00:17:03Z")

</div>

> [@anonymous\_user\_82dfa2f11](#):
>
> Step by step video for finding the angle between two 3D vectors written out: [https://www.youtube.com/watch?v=QWIZXRjMspI](https://www.youtube.com/watch?v=QWIZXRjMspI)

Already saw this one. My issue is that vector a is at (0, 0, 0) and vector b is at some other random location like (600, 0, 150). Using the fomular from the video is somewhat useless to me, because of the vector a at (0, 0, 0). This is where Í don’t understand the math :). Or rather, how do find a solution to my issue.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_82dfa2f11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_82dfa2f11](https://forums.unrealengine.com/u/anonymous_user_82dfa2f11)\
**Post date:** [May 24, 2020, 12:26am UTC](https://forums.unrealengine.com/t/get-the-highest-slope-along-a-spline/144266/4 "2020-05-24T00:26:46Z")

</div>

Ah, ok. You’re simply talking about finding the slope between two points in space. I think this is what you’re after then: [http://quiz.uprm.edu/visual3d/manual…lope\_line.html](http://quiz.uprm.edu/visual3d/manual/coor_sys/slope_line.html) Rise over run. Rise is the difference between their Z values. Run will be finding the distance between the two points in the XY plane.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_82dfa2f11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_82dfa2f11](https://forums.unrealengine.com/u/anonymous_user_82dfa2f11)\
**Post date:** [May 24, 2020, 1:04am UTC](https://forums.unrealengine.com/t/get-the-highest-slope-along-a-spline/144266/5 "2020-05-24T01:04:45Z")

</div>

Or do you mean that your conveyor segments are represented as vectors (direction and magnitude), but they have completely different locations (0,0,0 and 600,0,150)? Their locations do not matter. You can still apply the formula to find the angle between them.

---

<div class="post-metadata">

**Author:** ![Rumbleball](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rumbleball](https://forums.unrealengine.com/u/Rumbleball)\
**Post date:** [May 24, 2020, 1:08am UTC](https://forums.unrealengine.com/t/get-the-highest-slope-along-a-spline/144266/6 "2020-05-24T01:08:04Z")

</div>

assuming that the in and out of the conveyer are horizontal, the biggest slope is in the middle of the spline.

Somewhat like this. dunno if the function names are 100% correct

```auto

FVector direction= Spline->GetDirectionAtDistanceAlongSpline(Spline->GetSplineLength()/2);
float slope = FMath::Abs(direction.Z / FMath::Sqrt(direction.X*direction.X + direction.Y * direction.Y)); // Abs cause the slope might go down and you want only positive values for your comparison.

```
