Solved

Points parallel to Bezier Curve

Posted on 2014-02-28
5
678 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
array6 challenfge 6 62
allStar challenge 1 41
countAbc challenge 9 49
Program to display an alert on Windows Toolbar 2 65
We are taking giant steps in technological advances in the field of wireless telephony. At just 10 years since the advent of smartphones, it is crucial to examine the benefits and disadvantages that have been report to us.
A short article about problems I had with the new location API and permissions in Marshmallow
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

706 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

18 Experts available now in Live!

Get 1:1 Help Now