Skip to main content
gamedev.net
🔒 Locked

Parallel polylines

Started by Erkki 3 replies 950+ views
Original Post
Erkki
Erkki
My program draws roads consisting of beziers and polylines. But I''m having trouble making parallel polylines. If I know points A,B,C on the polyline, how do I find for point B the normalized vector pointing to the edge of the road? I came up with a complicated method of finding it, but it gives me errors with some angles. In the below image, how do I find the white point when I know the blue points? Maybe I should just use single lines instead of polys and connect the lines with curves?
oliii
oliii
usually, by deriving the central curve, you get the direction the curve is going at a point.

in 3D, by doing a second derivative (derive again one more time), you get the direction you need.

In 2D, you don't have to worry about dicontinous curves. Just calculate the direction D(x, y) at the blue point, and the vector perpendicular to it will have a direction (y, -x).

Deriving is simple with polynimial curves, so it should be easy. However, on some type of curves (catmull-rom), the second derivative is not continuous apparently, so it doesn't alway work.

example
-------
x = t^3 * a3 + t^2 * a2 + t * a1 + a0
y = t^3 * b3 + t^2 * b2 + t * b1 + b0

x' = t^2 * (3*a3) + t * (2*a2) + a1
y' = t^2 * (3*b3) + t * (2*b2) + b1

and a3, a2, a1, a0, b3, b2, b1, b0 are usually calculated from the control points's position along respectively the x and the y axis.

x, y is the position of the point on the spline, given t.
x', y' is the direction of the spline at the point (x, y)

If the spline is discontinous in C2, you can take another sample point slightly before the blue point on the central curve, and a point after, join them in a segment, and compute the perpendicular direction of the blue point to the segment. A bit like a bow, where the segment is the rope, and the small curving bit between the points of the segment is the bow. Drawing a perpendicular line from that segment to the blue point in the middle would give you an arrow, pointing towards where the white point should be.

[edited by - oliii on August 29, 2003 4:40:45 PM]
Everything is better with Metal.
Erkki
Erkki
Thanx, but I already know how to do it with curves.

But I''m having problems finding the vector where two LINES join

Anyway, I decided that polylines don''t look good and I will only allow single lines so that two lines can''t be connected directly - there will have to be a curve between them. Looks better that way.
Erkki
Erkki
I figured out my mistake and now it works fine. If anyone is interested, I can draw an image of how it works. Here''s the source:


// the 3 points on the Polyline

Point p0 = (* points)[i - 1].point;
Point p1 = (* points)[i].point;
Point p2 = (* points)[i + 1].point;

Vector v1, v2, v3, v4, v5;
Point p3, p4, p5;
Coordinate a;

v1 = p1 - p0;
v2 = p2 - p1;
v3 = Vector(v2.y, - v2.x, v2.z).normalize();
v4 = Vector(v1.y, - v1.x, v1.z).normalize();

p3 = p1 + v3;
p4 = p1 + v4;
v5 = (p4 - p3) / 2;
p5 = p3 + v5;

// similar triangles

v = (p5 - p1);
a = v3.scalar();
v = v.normalize() * (a * a / v.scalar());

(* points)[i].sideVector = v;
Jankey
Jankey
Does this code also work for Spline Tunnels? .. *interessting*
J.A.N.K.E.Y.: Journeying Artificial Nocturnal Killing and Exploration Youth

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.