Solved

Points parallel to Bezier Curve

Posted on 2014-02-28
5
689 Views
Last Modified: 2014-03-03
I am developing an application that uses OpenGL and I need to create a series of parallel QUAD_STRIPS. You can think of it as a curved road with multiple lanes and I need to draw each lane separately. These lanes need to follow a set Bezier curve (with 2 control points) that is located along the center stripe of the road.

I can calculate the points along this cubic Bezier curve, but I am looking for a way to calculate a like number of points along both edges of each lane that parallels the center stripe that have a consistent offset or lane width if you will. If it matters, the initial curve can have any orientation in the Cartesian plane.
0
Comment
Question by:swestbrook60
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 39896430
A curve that's a fixed distance from a Bezier curve is not in general something as simple as another Bezier curve.
You might try just adding a perpendicular to the tangent, or try the methods here:
http://www.cis.usouthal.edu/~hain/general/Publications/Bezier/BezierFlattening.pdf
0
 
LVL 27

Assisted Solution

by:aburr
aburr earned 250 total points
ID: 39896686
Points will never be parallel to a line (center or otherwise.)

But you might draw a line perpendicular to your curve at a point on the curve and lay off a distance of 1/2 your lane width in both directions on that perpendicular. Select as many points on your curve as you think you need and connect all the added points with straight line segments. If the segments are not curvey enough for you, just select more points on the initial curve.
0
 
LVL 12

Accepted Solution

by:
satsumo earned 250 total points
ID: 39898509
You need to calculate perpendicular lines to the original curve then move the points of the curve out by some width. To calculate the perpendicular is actually not as hard as you might think. You find a tangent and then turn it 90 degrees by swapping and negating the X and Y (assuming that the curves is on the Z plane). The tangent is found by interpolating the direction between control points the same way you would interpolate between the position of each control point. By direction I mean the vectors from the start point to c1, c1 to c2, and c2 to the end point. Note that, under some conditions, doing this will cause the strip to overlap itself, that isn't a problem unless you want to render the curve with a texture or an edge. Also note that a cubic bezier (two control points) can cross itself in extreme cases.
0
 

Author Closing Comment

by:swestbrook60
ID: 39900717
Since they are similar answers I will split the points. These solutions gave me another idea too. That is to find the angle of each segment in the original cure, then offset a point the width of the lane at the segment midpoint. With staggered points I can use a GL_TRIANGLE_STRIP instead. I can always adjust the number of segments in the original curve to maintain a smooth result. Since no dramatic curves are expected this should give a fairly good rendering. I will try it and see how it works under various conditions.
0
 
LVL 12

Expert Comment

by:satsumo
ID: 39900926
Thanks for the points. I've actually written some code for doing just what you are doing, you have the right idea. The code I wrote was for a GPS device, to show road maps.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Nicole
This is a research brief on the potential colonization of humans on Mars.
This article provides a brief introduction to tissue engineering, the process by which organs can be grown artificially. It covers the problems with organ transplants, the tissue engineering process, and the current successes and problems of the tec…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now