Jump to content
• Advertisement

# C#/DX9 curve drawing problem/opinion

This topic is 3028 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## 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

##### Share on other sites
Advertisement
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

##### 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

##### 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

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
19
2. 2
3. 3
JoeJ
15
4. 4
5. 5
• Advertisement

• 18
• 19
• 10
• 13
• 17
• ### Forum Statistics

• Total Topics
631694
• Total Posts
3001751
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!