2

I have the coordinates of potentially any points within a 3D arc, representing the path an object will take when launched through the air. X is forward, Z is up, if that is relevant. Using any of these points, I need to create a bezier curve that follows this arc. The curve requires the tangent values for the very start and end of the curve. I can't figure out the formula needed to convert this arc into a bezier curve, and I'm hoping someone can help. I've found plenty of resources discussing circular arcs, but the arc here is not circular.

2 Answers2

1

Assuming that the arc is indeed a parabola, then the procedures outlined at Convert segment of parabola to quadratic bezier curve and http://www.ams.org/samplings/feature-column/fcarc-bezier should provide the appropriate calculations.

Alex Meiburg
  • 2,541
  • Ah, I'll look closer at those. I didn't think they applied here, since the formula given required A, B, and C variables without any definition given as to what those represented, so I was left to assume that they were unique to the calculation of a Parabola, and not applicable here. I've never taken Calculus, so I have a bit of a tenuous grasp on that. – Zack Maxwell Feb 06 '17 at 04:18
1

Let $\mathbf{Q}$ be the start of the curve, let $\mathbf{V}$ be the initial velocity vector, and let $\mathbf{G}$ be the gravity vector. Then the equation of the trajectory is: $$ \text{ParabolaFunction:}\quad \mathbf{P}(t) = \mathbf{Q} + t\mathbf{V} + \tfrac12 t^2\mathbf{G} $$ I will assume that you have unitized the time scale so that the flight starts at $t=0$ and ends at $t=1$.

Compute three points on the curve: \begin{align} \mathbf{P}_0 &= \mathbf{P}(0) \\ \mathbf{P}_m &= \mathbf{P}(\tfrac12) \\ \mathbf{P}_3 &= \mathbf{P}(1) \end{align} and let $\mathbf{P}_c = \tfrac12(\mathbf{P}_0 + \mathbf{P}_1)$ be the mid-point. Compute $$ \mathbf{P}_a = \mathbf{P}_c + 2(\mathbf{P}_m - \mathbf{P}_c). $$ Then let \begin{align} \mathbf{P}_1 &= \tfrac23\mathbf{P}_a + \tfrac13\mathbf{P}_0 \\ \mathbf{P}_2 &= \tfrac23\mathbf{P}_a + \tfrac13\mathbf{P}_3 \end{align} Then the control points of the cubic Bezier curve are $\mathbf{P}_0$, $\mathbf{P}_1$, $\mathbf{P}_2$, $\mathbf{P}_3$.

Pseudocode is as follows. It assumes that addition and scalar multiplication of 3D points and vectors have been overloaded in the obvious way:

p0 = ParabolaFunction(0)
pm = ParabolaFunction(0.5)
p3 = ParabolaFunction(1)

pc = 0.5*(p0 + p3)      // Point on chord
pa = pc + 2*(pm - cc)   // Apex point; intersection of tangents

oneThird = 1.0/3.0
twoThirds = 2*oneThird 

p1 = twoThirds*pa + oneThird*p0
p2 = twoThirds*pa + oneThird*p3

result = CubicBezierCurve(p0, p1, p2, p3)
bubba
  • 44,617
  • Hm... I'm really struggling with this one. It doesn't account for the Y-axis, so I had to put that in myself, which I attempted by just replicating the X-axis math on it. It also has some extraneous bits, since I already have the basic points in the parabola. My attempts so far have failed, though. I'm just getting a straight line as the bezier curve. – Zack Maxwell Feb 09 '17 at 21:02
  • From your question, I got the impression that your parabola was just $z$ as a function of $x$, with $y=0$ everywhere. If that's not the case, then the approach will need to be modified. Please clarify. – bubba Feb 10 '17 at 00:39
  • Do you actually have the ParabolaFunction that I assumed? If so, what are its inputs and outputs? – bubba Feb 10 '17 at 01:02
  • I... don't think I have a ParabolaFunction. I'm using X, Y and Z. I was simply stating that Z in my case is the up axis, but saying X is forward may have been misleading. I forgot that I was actually using world coordinates. – Zack Maxwell Feb 10 '17 at 02:43
  • What do you know about your "arc"? Do you know its equation? Do you have some points that lie on it? Can you calculate a point at any given "time" value? You're asking for a function that outputs a Bezier curve; you have to specify what inputs this function will receive. – bubba Feb 11 '17 at 03:08
  • It's calculating the path a physics projectile will take, so I'm performing a series of ray traces along an arc. The math used to determine where each point of the trace should be is a bit complex, but I can store any of them as a variable. Currently the arc spans 5 seconds of flight, with a point every 0.05 seconds, so a max of 100 points. I'm trying to use the bezier curve to visually represent the path plotted by these points. – Zack Maxwell Feb 11 '17 at 18:10
  • For the actual math, I'm taking the initial location and velocity of the projectile as variables, as well as the Duration (5), Delta (0.05), and force of Gravity. Number of points in arc (MaxIndex) = Duration / Delta rounded. Perform loop from 0 to MaxIndex. Inside loop, perform ray trace using Location + (loop index * Delta * Velocity) + (loop index * Delta ^2 / 2 * Gravity) I use this formula with normal loop index for the starting point of the trace, and loop index +1 to get the end point of the trace. – Zack Maxwell Feb 11 '17 at 18:38