Sign in to follow this  
Geometrian

3D Line Equation

Recommended Posts

Quote:
Original post by Geometrian
Hi,
I'm trying to make a ray-tracer. I would like to know what the equation of a line is, in 3D, if I specify two 3D points.
I haven't done much work with ray tracing, but generally in 3-d graphics we work with linear components using the parametric form, i.e.:
P(t) = O + tD;
Where O represents a point that lies on the linear component, and D is the linear component's direction vector.

For rays, O is generally taken to be the origin of the ray, and D is generally normalized (it isn't strictly necessary for the direction vector to be unit-length, but it does simplify things somewhat).

Share this post


Link to post
Share on other sites
My idea was to:
1. Make equations for each ray, where each ray goes through both the eye point and the given pixel.
2. For each object, each with its own equation as well, determine the solutions to the system of equations.
3. I take the closest solution, and go from there.

Share this post


Link to post
Share on other sites
A + va

or

A + n(va)*size

or

A + (B-A)

or

U(i) = A + i*va for 1 > i > 0

If you would like to do raytracer, you should remember a pixel isn't infinitelly thin. (And perfect calculation are contradictory with idea of raytracer.)

Share this post


Link to post
Share on other sites
Quote:
Original post by Geometrian
My idea was to:
1. Make equations for each ray, where each ray goes through both the eye point and the given pixel.
2. For each object, each with its own equation as well, determine the solutions to the system of equations.
3. I take the closest solution, and go from there.


This is more or less how it is performed. There are not many good free resources on the topic over the internet. A classic start point is this 7 parts tutorial from Jacco bikker (author of the arauna real time raytracer project).

For more advanced discussions you could give a look at the www.ompf.org site.

There are not really as many resources as one would expect for a so fascinating topic. If you're serious, buy a good book. There are a few very good ones out there. I would personaly suggest pysically based rendering as it contains an ipressive number of topics explained with a extraordinary quality, but it is also a bit hard to read: it is not 'progressive', it 'just' explains the high quality renderer they developed, covering from the ground topics like sampling, camera and light models, geometry-ray intersection, global illumination, shading and so on. It is an advanced book (as I discovered when I buied it), but a must have.

Just one more note: jyk said that the direction must not be normalized. Since you then said that you want to build a RT, I only add that for all pratical pourposes, the direction will be quite always be of unit length...

[Edited by - cignox1 on February 21, 2008 1:20:18 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by cignox1
...jyk said that the direction must not be normalized...
Just to be clear, I said that it's not strictly necessary that the direction vector be normalized (a true statement).

However, as you note, you usually will want to normalize the direction vector in practice (especially in the context of a ray tracer).

Share this post


Link to post
Share on other sites
OK, new problem:
given a line determined by two points, find the point of intersection, if any, with a triangle defined by three points.
def CollideTest(LinePoint1,LinePoint2,([x1,y1,z1],[x2,y2,z2],[x3,y3,z3])):
#?
#return:
#None - No solutions
#Infinite (return None)
#one point (x,y,z)

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
Quote:
Original post by cignox1
...jyk said that the direction must not be normalized...
Just to be clear, I said that it's not strictly necessary that the direction vector be normalized (a true statement).


Sorry, my fault: I meant this, but my poor english prevented me from formulating it better :-(.

Share this post


Link to post
Share on other sites
Quote:
Original post by Geometrian
OK, new problem:
given a line determined by two points, find the point of intersection, if any, with a triangle defined by three points.*** Source Snippet Removed ***


There are many ways to accomplish this task.
this is a quite common algorithm. One of the faster (if not the fastest one) general pourposes routines wich don't require additional precommputed data.

Share this post


Link to post
Share on other sites
I've found cgkit. Following the documentation it should provide a ry-mesh intersection function, but I don't know if the ra-triangle routine is written in python or in c++. You will need to download it and give it a try. Unless you want to implement it anyway, you could always use that library...

Share this post


Link to post
Share on other sites
Yes, I saw the collision thing in cgkit, however, I've had some problems with other programs using cgkit, and I would anyway not like to make my package dependent on another library. If there were some way to get only the souce for the collision, in Python, and paste that into my main, it would solve my problem.
Thanks,
G

Share this post


Link to post
Share on other sites
Unluckily I don't know python well enough to translate the code of the pasper. If you don't know anybody that can help you with that (you may want to open another thread for this) you can always try to do it yourself, perhaps following the description in the paper. Anyway, the code itself does nothing really fancy, so you should be able to rewrite it in python wothout studing c first. Just be careful with pointers :-)

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