How to create a 1D Curve?

I have a line with a couple of numbers that I would like to use to generate a 1-dimensional “height” curve. ThreeJS has some excellent abstractions for dealing with curves–in particular, getSpacedPoints of the Curve class makes it easy to get evenly spaced segments along any curve.

For exampe, SplineCurve is a Curve<Vector2> and CatmullRomCurve3 is a Curve<Vector3>. These are almost what I need, but they actually do too much by operating in 2 or 3 dimensions. Apparently, the parametric type T of Curve<T> must be a Vector. Is there a way to create a Curve<Vector1> somehow?

(There is no Vector1 class in threejs, so I guess I’m looking for alternative ways to think about it or implement such a Curve…)

Hi!
Vector1 is just a number of float or integer :thinking:

How does that curve have to look like? Any explanatory picture?

three.js always renders in 3D. When you have 2D curve definition, the data are usually defined in the XY plane which means the Z coordinate is always zero.

In the 1D case that means Y is zero, too. Such you just have values along the (1,0,0) cardinal axis which means you end up with a simple line. Is that what you are looking for?

1 Like

Vector1 is just a number of float or integer

Yeah, that’s why it’s weird that T is constrained to be a Vector subtype in Curve<T>.

How does that curve have to look like? Any explanatory picture?

Here’s a sample from the app I’m writing. A 2D curve is the path of the text, while a 1D curve is needed to calculate the height of the text at each point along the curve:

I had originally used a Vector3 to combine it (using the Z value to represent height) but it turned out that overloading the Z value in this way made laying out the text slightly distorted in some cases.

In the 1D case that means Y is zero, too. Such you just have values along the (1,0,0) cardinal axis which means you end up with a simple line. Is that what you are looking for?

Yes, I ended up using a SplineCurve and ignoring the Y value (setting all control point Y values to 0).

1 Like