Re: [osg-users] Intersection of two lines

2011-09-07 Thread Shayne Tueller
I am not aware of a function in OSG to do this, however, you can do it yourself.

If you have a starting point and direction for each line, you can define each 
line parametrically as

Line 1: P + rA
Line 2: Q + sB

where P,Q are the starting points and A,B are the unit direction vectors. The 
scalars r,s are what we want to solve for. This can be done by equating the two 
lines

P + rA = Q + sB or rA - sB = Q - P

For 2D, this is a simple 2x2 linear system. The scalars r,s can be uniquely 
solved for by using Cramer's rule (stable for small systems). Of course, this 
assumes that the lines are not parallel or on top of each other (check for this 
first). Once the scalars r,s are solved for, plug them back into Line 1 or Line 
2 to get the point of intersection in your coordinate system.

For 3D, the system above turns into an overdetermined system of equations (i.e. 
3 equations and 2 unknowns) which does not have a solution except when the 
system contains linearly dependent equations.

For the case where there is no solution, you can solve for a point of 
intersection in a least squares sense using the method of normal equations. 
This method is numerically stable for small systems. To do this, write the 
system above as

Cx = d

where C is a 3x2 matrix, x is a 2x1 column vector containing the scalars r,s we 
want to solve for, and d is 3x1 column vector. Using the method of normal 
equations, we can rewrite the system to be

CtCx = Ctd

where Ct is the transpose of C. This new system now becomes a 2x2 linear system 
which can be solved like the 2D case above.

Hope this helps...

-Shayne

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=42509#42509





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Intersection of two lines

2011-09-07 Thread Vincent Bourdier

Hi,

Using a simple system equation you should find it.
Just google it...

Regards,
   Vincent.

Le 07/09/2011 11:32, Andreas Roth a écrit :

Hi,

this maybe a stupid and simple question. I have two lines and i want to 
calculate the intersection point of the two lines.
For both lines is have a starting point and the direction. Is there a function 
to calculate the intersection point?

Thank you!

Cheers,
Andreas

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=42478#42478





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Intersection of two lines

2011-09-07 Thread Andreas Roth
Hi,

this maybe a stupid and simple question. I have two lines and i want to 
calculate the intersection point of the two lines.
For both lines is have a starting point and the direction. Is there a function 
to calculate the intersection point?

Thank you!

Cheers,
Andreas

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=42478#42478





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org