Jump to content
  • Advertisement
Sign in to follow this  
mitte

implementing streamtube

This topic is 4203 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, Now i'm implementing streamtube using c/c++ as implemented in Matlab. It is difficult to implement linking part. I searched vector visualization, but I couldn't get any information about implementing streamtube. Is there any other information about that? Thanks,

Share this post


Link to post
Share on other sites
Advertisement
By streamtube do you mean the following?
http://mayavi.sourceforge.net/screenshots/office_tube.gif

What specific difficulty are you having? By linking, do you mean connecting subsequent cylinders smoothly? If so then I recommend the following. Keep in mind that I'm drawing from my memory of first year physics, so the information may not be even remotely accurate :)

I recommend orienting the end faces of the cylinders so that the plain that the face lies on also contains the vector from your sample point on the curve to the center of curvature at that sample point. I believe that this requires differentiating the curve twice with respect to the axis defined by the curve. You could also optimize the performance and look of your render by sampling more frequently at places where the first differentiation is higher. Nurbs or splines seem suited to this sort of application.

Hope this helps,
- llvllatrix

Share this post


Link to post
Share on other sites
Thank you for your advice,

I encountered at linking part smoothly. You knows my problem exactly.

my code as following.

1. read vertices

2. make cylinder with specific radius and height where is the eulidean distance from current vertex to next vertex

At second step, I have a problem that connecting vertex does not be drawn smoothly as shown in hyper-link you wrote.

What kind of books or website will be helpful to me?


Regards,

Share this post


Link to post
Share on other sites
Unfortunately, I dont think this kind of problem is too common so there probably is not a lot of documentation (that I'm aware of) on the subject. You are probably going to end up looking at a lot of physics and mathematical papers to collect the parts you need to solve the problem. Gamedev (http://www.gamedev.net/reference/list.asp?categoryid=28) and gamasutra are good resources in this regard.

Further, having a digitized sample (verticies) of your curve means that to get better resolution, you must interpolate. If this is for professional(engineering) use, you may have to clear the topic of interpolation with someone.

Perhaps the best thing you can do is post a screenshot of your application so far and we can give you specific advice on how to improve the result. Lesson 36 (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=36) describes a similar process, but unfortunately the code used in the lesson is very specific to the lesson.

Here is a quick description of what I would do to solve this problem.

1. Read verticies

2. Interpolate the verticies.

In order to produce a smooth result, you will need to be able to retrieve
the location of the particle at any point in the curve; even points between
the verticies sampled. Bezier splines (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=28)
and NURBS (http://www.gamedev.net/reference/list.asp?categoryid=28#262)
are suited to this application.

3. Convert the verticies into mathematical representations as needed.

You will require a variety of information in order to do this render. You will
need information that will let you allign the faces of the cylinders and information
that will let you sample your curve so that the majority of the detail is captured
(optional) in the render. For this discussion lets say the position of the particle
at time t is defined by p(t) = x(t)i + y(t)j + z(t)k (I expect a different
representation might be easier to calculate from the information you're given).

4. Use the mathematical representations to generate the tube.

The first derivitive of p(t) with respect to t will give you a vector that is tangent
to the curve; this is the velocity vector. The second derivitive will give you the
acceleration vector. The acceleration vector has two components; one that is tangential
to the curve, and one that points in the direction of the centre of curvature at a
given time t (this model is called curvalinear motion). You can use these two
components to properly orient the face of each cylinder at time t. In order to get
isolate the components, you can use the velocity vector. If you normalize it, you can
project the acceleration vector onto it to get the tangential component. You can then
subtract this component from the original acceleartion vector to get the radial
component (the component that points to the center of curvature).

You can also use the radial component to determine where the curve needs to be
sampled more. The magnitude of the radial component indicates how quickly the
curve is changing direction. Use few samples where the curve is not changing
direction a lot and a lot of samples where it is changing rapidly. The result
should be a smoother curve that renders faster.

5. Render the tube.

If the tube is going to be very large, consider sometthing like a vertex buffer object.

Hope that helps,
- llvllatrix

Share this post


Link to post
Share on other sites
Hi,

I solve this problem 90%. Thank you.

<Solved>
as you mentioned, I used vertex interpolation using linear.

new_vertex = v1 + d*(v2-v1)/n
(where d: step, n: interpolation count)

The linking part seems to be a curve.
(How can I show my results?
(Is there any useful ftp or web-server freely?

<not solved>
By using interpolation, the normal vector is changed to opposite direction.
Before applying the interpolation, the normal vector can be calculated easily.
After applying that, the normal vector has changed.

my code is below..

//---
for(i=0; i<n; i++) {
v1 = m_array.GetAt(j);
v2 = m_array.GetAt(j-(ncount-1));
v3 = m_array.GetAt(j+1);
v4 = m_array.GetAt(j+ncount);

normal = CalcNormal(v1, v2, v3);
glNormal3f(normal.x, normal.y, normal.z);

glBegin(GL_QUADS);
DrawVertex(v1);
DrawVertex(v2);
DrawVertex(v3);
DrawVertex(v4);
glEnd();
}
//---

//---
VERTEXf CalcNormal(VERTEXf v1, v2, v3)
{
VERTEXf a, b, n;
GLfloat sum=0;

a.x = v2.x - v1.x;
a.y = v2.y - v1.y;
a.z = v2.z - v1.z;
b.x = v3.x - v1.x;
b.y = v3.y - v1.y;
b.z = v3.z - v1.z;
n.x = a.y*b.z - a.z*b.y;
n.y = a.z*b.x - a.x*b.z;
n.z = a.x*b.y - a.y*b.x;
sum = (GLfloat)sqrt(sqr(n.x)+sqr(n.y)+sqr(n.z));
n.x = n.x/sum;
n.y = n.y/sum;
n.z = n.z/sum;

return n;
}
//---

Calculating normal vector using 4 vertices could be wrong.
I don't know exact equation to get normal vector.

Best regards,

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

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!