Author |
Message |
|
simonzack
Advanced Newbie
Joined: 25 Dec 2007 Posts: 71
|
Posted: 19 Jan 2008 09:51:00 am Post subject: |
|
|
For my 3D engine, I need to solve the following problem:
they're two lines, x1,y1,z1-x2,y2,z2 and x3,y3,z3-x4,y4,z4
on the XY plane, get the intersection point, which z is bigger for two lines at this intersection point?
I got the intersection point, did the z, but the comparing process involved massive calculation. Does someone have a quicker way to do this, manually, or like Mathematica or something? thanks
(I tried it on calc, and I waited patiently, it never solved it... ) |
|
Back to top |
|
|
thornahawk μολών λαβέ
Active Member
Joined: 27 Mar 2005 Posts: 569
|
Posted: 19 Jan 2008 11:06:17 am Post subject: |
|
|
I don't quite understand what you want. Did you mean the intersection of the two lines passing through those respective points, the intersection of the two segments through those points, the intersection with the x-y plane (trivial), or something else?
The "bigger z"... the coordinate? Do try to be clearer.
thornahawk |
|
Back to top |
|
|
simonzack
Advanced Newbie
Joined: 25 Dec 2007 Posts: 71
|
Posted: 19 Jan 2008 09:46:29 pm Post subject: |
|
|
It's like calculating the intersection for (x1,y1)-(x2,y2) and (x3,y3)-(x4,y4) to (x,y), then for this (x,y) on each of the two lines, there would be a different z value,
so compare these two z values
I hope that makes it clearer... |
|
Back to top |
|
|
sgm
Calc Guru
Joined: 04 Sep 2003 Posts: 1265
|
Posted: 19 Jan 2008 10:01:14 pm Post subject: |
|
|
So you have two three-dimensional lines, and from that you
- Discard the applicate (the z-component), giving two two-dimensional lines.
- Find the coordinates of the intersection of these two 2-D lines.
- Move this 2-D point of intersection back into 3-D, and get its applicate.
Does this clearly describe what you want?
Last edited by Guest on 19 Jan 2008 10:02:02 pm; edited 1 time in total |
|
Back to top |
|
|
simonzack
Advanced Newbie
Joined: 25 Dec 2007 Posts: 71
|
Posted: 20 Jan 2008 02:01:16 am Post subject: |
|
|
Quote: Does this clearly describe what you want?
Yeah, and compare the 2 z values applicated |
|
Back to top |
|
|
simonzack
Advanced Newbie
Joined: 25 Dec 2007 Posts: 71
|
Posted: 20 Jan 2008 05:27:21 am Post subject: |
|
|
I haven't solved this yet, but found a great CAS--Axiom, probably you've heard of this. It's got all the stuff calcs have, and the web said over 1000 funcs, with 3D support. And it's real quick when I tried it. This is great |
|
Back to top |
|
|
CoBB
Active Member
Joined: 30 Jun 2003 Posts: 720
|
Posted: 20 Jan 2008 06:52:10 am Post subject: |
|
|
It depends on how you project the lines to the plane. If the projection simply means discarding the z coordinate, then all you have to do is write parametric equations for the two projected lines this way:
xa(t) = x1 + (x2-x1)t
ya(t) = y1 + (y2-y1)t
xb(t) = x3 + (x4-x3)t
yb(t) = y3 + (y4-y3)t
Then find t1 and t2 such that xa(t1) = xb(t2) and ya(t1) = yb(t2). This gives you a system of equations that can always be solved if the lines are not parallel on the plane (that will lead to a zero denominator somewhere that you can obviously detect). You can use these t1 and t2 values to calculate the corresponding z coordinates by plugging them in the three-dimensional extension of the above formulae:
za = z1 + (z2-z1)t1
zb = z3 + (z4-z3)t2
That’s all there is to it.
If you have a perspective projection where you divide x and y by z to get their planar coordinates, you can still use the same equations to obtain t1 and t2 (by writing x1/z1 instead of x1, y3/z3 instead of y3 etc.), then interpolate the reciprocal of z instead of z itself:
1/za = 1/z1 + (1/z2-1/z1)t1 -> za = 1/(1/z1 + (1/z2-1/z1)t1)
1/zb = 1/z3 + (1/z4-1/z3)t2 -> zb = 1/(1/z3 + (1/z4-1/z3)t2)
I hope there are no typos, but the basic idea should be clear. |
|
Back to top |
|
|
simonzack
Advanced Newbie
Joined: 25 Dec 2007 Posts: 71
|
Posted: 21 Jan 2008 08:09:57 am Post subject: |
|
|
Ah, finally, I got a better CAS and worked it all out in no time at all, looks like the calculator needs to improve it's speed badly...
Thanks a lot for the help Cobb, I considered another way, but u reminded me of the T thing I forgot to use. It can optimize my program lots, and I don't need to factorize the expressions. |
|
Back to top |
|
|
|