Calculate Spline Tangent

I took a look at it, and don’t think that this is exactly what i need. I just want to bend the end of the meshes, so that I have like 10 meters straight and then only bend the mesh at the point so that the lines match. Maybe it helps your understanding if I tell you that I want to do streets with it.

But is it possible to achieve what I want?

Hi,

I have to calculate a spline tangent manually, because I don’t update the spline and just have the points.

I want to blend the meshes together at the corner.

I draw a pic to visualize it:

So I have to calculate the purple tangent given the Splinepoints.

My problem is also, that I don’t know where the tangent vector has to “point at” to get this spline turn, because I can’t find any documentation on it.

It doesn’t matter if your solution is BP c++ or just an explanation. Every help is appreciated.

Thanks in advance!

Hello! You can tray to use cubic interpolation, that is used in many places. The main idea is if you have start point P0 and tangent T0 with end point P1 and end tangent T1, then you can construct cubic approximation

(((2x^3)-(3x^2)+1)P0) + ((x^3-(2x^2)+x)T0) + ((x^3-x^2)T1) + (((-2x^3)+(3x^2))P1)

where x is from [0, 1]. At 0 it gives you P0 point and T0 tangent, while at 1 it gives you P1 and T1. So, when x is some value inside interval, you get interpolation point and tangent

1 Like

Ok, I see. I have’nt worked with USplineMeshComponent at the moment, but I will check it…

Alright thank you :smiley:

Are you still on it? Got an idea: I could put 2 spline mesh components together, one for the straight line and one just for the curved part.

This should work out, but still not my favorite solution. Mostly because of performance.

Hi there! Take a look at this Unreal Engine 4 Guide - Spline component - road, pipe, railroad - YouTube. This is the way you can use it and dont calculate tangents by hand

I think you still missunderstand me, sry if my problem is so unclear. I know that I could get the tangent like this, but my problem is, that I add points at runtime, And I don’t want the existing splines to change (because streets dont move). So I set bUpdateSpline parameter to false.

And then I get only points and the splines are straight lines.

There is one important thing - to calculate spline between two points you must have point locations and point tangents as well, they are input data for spline. Because of that you need a method to get tangent, maybe heuristic. You cant get tangents from alone points, there should be some conditions to get one.
When you add points at runtime you have info about the nearest existing point to it, right? And as I understand you are adding points outside of existing segments.

I wanted to just bend the end of the mesh and most part of mesh is straight, but I think for this you have to seperate it into 2 meshes.

Anyways, I found a better solution. My problem was that I don’t want to change spline when adding points and I found a solution for this. Before I add a new point I save the arrivetangent of the last point and after placing the new point I reset the arrivetangent so the existing spline doesnt change and I still have a good looking way

Yes, that is rather logical step. All data has no changes, but the last existing point and new point has some.