Cone vector math. Making points on local circule

So i’m trying to make equally distributed points around the central one, preserving the plane angle. Central point it’s a spline point. For calculation i make 3 vectors i.e. local axis (X,Y,Z).
FRotator centrToNext = UKismetMathLibrary::FindLookAtRotation(CoreSplinePath->GetLocationAtSplinePoint(i, ESplineCoordinateSpace::World), CoreSplinePath->GetLocationAtSplinePoint(i + 1, ESplineCoordinateSpace::World));
FVector v1 = centrToNext.Vector(); // direction from currenter center point to next
FVector p = CoreSplinePath->GetRightVectorAtSplinePoint(i, ESplineCoordinateSpace::World); // local X and Y axis
FVector q = FVector::CrossProduct(v1, p);
Then calculating result point
FVector res = radius * (p * FMath::Cos(currentAngle) + q * FMath::Sin(currentAngle));
Angle is 0, 120 or 240 - depending on cicle step. Then add central point location to result;
CentralPoint += res;
But after creation the angle is not what i expected. If compare them to 0 angle i’ll recieve 0, 35 and 70 degree. Why does this happends? (I’m not good at vector math, sry)

If I understood correctly, perhaps consider this way:

	// How many along path.
	const int32 StepsAlongPath = 10;
	const float StepLength = Spline->GetSplineLength() / float(StepsAlongPath);
	// How many around point.
	const int32 StepsAlongCircle = 5;
	const float StepAngle = 360.f / float(StepsAlongCircle);
	
	// Distribute along path.
	for (int32 i = 0; i < StepsAlongPath; ++i)
	{
		const float DistanceAlongSpline = float(i) * StepLength;
		const FVector LineStart = Spline->GetLocationAtDistanceAlongSpline( DistanceAlongSpline, ESplineCoordinateSpace::Local);
		const FVector RightAngleDistAlongSpline = Spline->GetRightVectorAtDistanceAlongSpline(DistanceAlongSpline, ESplineCoordinateSpace::Local);
		const FVector DirAtDistanceAlongSplie = Spline->GetDirectionAtDistanceAlongSpline(DistanceAlongSpline, ESplineCoordinateSpace::Local);

		// Distribute around point.
		for (int32 y = 0; y < StepsAlongCircle; ++y)
		{
			// Get new direction vector around point.
			const FVector RightAngleDistAlongSpline_Offset = UKismetMathLibrary::RotateAngleAxis(RightAngleDistAlongSpline, float(y) * StepAngle, DirAtDistanceAlongSplie);
			const FVector LineEnd = RightAngleDistAlongSpline_Offset * 10.0 + LineStart;

			// Local to world for debug.
			const FVector Start_World = UKismetMathLibrary::TransformLocation(GetActorTransform(), LineStart);
			const FVector End_World = UKismetMathLibrary::TransformLocation(GetActorTransform(), LineEnd);
			DrawDebugDirectionalArrow(GetWorld(), Start_World, End_World, 6.f, FColor::Red, false, 10.f, 0, 1.f);
		}
	}

Thx for answer, but i have manage this in differend way. I symply make a point at zero angle and then rotate point arround cone axis (v1). Also calculating the angle difference between spline mesh segments right vector, to preserve helical structure. Works fine to me.

FVector res = radius * (p * FMath::Cos(0.0f) + q * FMath::Sin(0.0f));
float shiftAngle = FMath::RadiansToDegrees(FMath::Acos(p.GetSafeNormal().Dot(FVector(1, 0, 0))));
res .RotateAngleAxis(currentAngle - shiftAngle , v1.GetSafeNormal());
FVector FinaleLocation = CentralPoint + res;

Glad it works. Just some notes on what you have.


If what you want is the direction along the curve, all you need is GetDirectionAtDistanceAlongSpline().

q * FMath::Sin(0.0f)) will always be 0.0 and p * FMath::Cos(0.0f) will always be p. So in reality all you are getting is FVector res = radius * p;. What you tried here is the equation in Polar Form of Complex Numbers and it’s to be used like so: radius * (x * cos(θ), y * sin(θ)), x and y are scalars, not vectors.

This returns the direction vector in world space since you specified ESplineCoordinateSpace::World.

GetUpVectorAtSplinePoint() should return the same. No need for cross product.


Hope it helps.

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