How to make curve geometry?

Is it possible to make some sprites / objects for copying and bending a curve? I made an image to show what I mean:

road

Here the curve, perhaps the beige path is green and the geometry is black. I want the sprite or object (on the left) to copy itself and combine it with the last copy, and the last two vertices follow the curve. If so, how to do it? Is there any documentation on this? Did you do something like that? How?

EDIT: I don't want the sprite or object to move along the path, but it seems to duplicate itself and merge with it, copying.

+5
source share
2 answers

Yes, what you want to do may work, and your drawing shows how it works quite well. The pseudocode will look something like this:

curveLength = <length of entire curve>; tileLength = <length of 1 tile>; currentLength = 0; while (currentLength < curveLength) { currentTileLength = 0; startPt = prevPt = calculateBezierAt(0.0); for (t = delta; (t < 1) && (currentTileLength < tileLength); t += delta) // delta is up to you. I often use 1/100th { nextPt = calculateBezierAt(t); distance = distanceBetween(prevPt, nextPt); currentTileLength += distance; currentLength += distance; prevPt = nextPt; } endPt = prevPt; // Calculate quad here } 

To calculate each quad, you need to create perpendiculars at the start and end points. You then have 4 points for your ATV.

Note that I simplified by assuming there is only one bezier. Usually you will have many of them related to each other, so it will be a little harder to sort them out than I said above, but it should not be too difficult.

Also note that if you have either very tight angles or the curve goes back, you may get poor results. Presumably, you will avoid this if you yourself generate curves.

+2
source

Take a look at SCNShape, which generates SceneKit geometry with a Bezier curve.

0
source

Source: https://habr.com/ru/post/1260365/


All Articles