3D Line Equation

Started by
13 comments, last by Geometrian 16 years, 1 month ago
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.

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Advertisement
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).
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.

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

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.)
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]
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).
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)

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

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 :-(.
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.
I looked through it, but I couldn't get the code working. It would be great if I had some code in the language I am most familiar with, Python.
Thanks,
G

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

This topic is closed to new replies.

Advertisement