Solved

Points parallel to Bezier Curve

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

8 Experts available now in Live!

Get 1:1 Help Now