Sign in to follow this  
Carbon_PhD

C#/DX9 curve drawing problem/opinion

Recommended Posts

Hi all, This is my first post so apologies if i dont quite have the programmers lingo. I have been learning C# for a month now (originally a VB user and very basic at that). My programming skills are quite limited so here goes... Program: In my directx space I deposit loads of line segments onto a floor as shown in the images. The lines are drawn via the end points and intersection points between segments are stored. Problem: Each segment is deposited one after the other but at crossover points I want to offset the z value and draw a curve through the points. Eventually after a lot of segments have been deposited I will have made a 3D fibrous material (a bit like loft insulation :0). Curve Drawing: So essentially I want to pass a line through the crossover points using a curve drawing function. I am using DirectX with C# and have researched and found this D3DXVec3CatmullRom function used however I cant seem to access it on my program. Material on this is quite dated so I wanted peoples opinion on whether this is the only option. Requirements: I actually need to capture the XYZ coordinates of each segment along intervals of each line. The reason for this is I need to export the data to a finite element package. I also need a compressing function to force the line segments into a given volume space but ensure the lines do not intersect. But this maybe to ambitious for the time being. Thanks in advance.

Share this post


Link to post
Share on other sites
Generally in D3D curves are approximated as a sequence of short straight lines. The shorter they are the better the curves will look.

A fairly simple method for curve drawing is to use a bezier curve which is defined by four control points, with a simple formula to find the coordinate of any point along the line. See http://en.wikipedia.org/wiki/B%C3%A9zier_curve or http://www.math.ucla.edu/~baker/java/hoefer/Bezier.htm for details.

Share this post


Link to post
Share on other sites
You don't need to actually use D3DXVec3CatmullRom, the documentation gives you all of the information needed to implement it yourself. D3DXVec3Hermite is also available, which is a different type of interpolation.

With any type of spline interpolation you're going to provide control points and a distance along the curve, and you'll get a position as output. Basically what you'll do is calculate discrete positions at N points along the curve and create straight line segments between those positions. The more points you use, the better it will look.

Share this post


Link to post
Share on other sites
Thanks Adam but I was looking for more control and need the spline to pass through the points not approximate close to them.

Looks like the catmull-rom or hermite is the right way to go. I was just hoping to be able to use the function itself as opposed to coding it myself but I will give it a go Matt thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this