🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.borland
Article #20

Re: 3d programming

#20
From: Christopher H. Clark
Date: Wed, 07 Feb 1996 04:56
65 lines
3492 bytes
James Derrick wrote:
> 
> In article <4f3od9$2jg@zeus.tcp.co.uk>, agale@agale.tcp.co.uk (Aaron Gale)
> wrote:
> 
> > Does anyone know how to find the intersection of a line and plane
> > in simple x,y and z cartesian coordinates.  I have a model made
> > up of facets, each facet being defined by 4 points.  The working
> > envelope that this model is in, is then scanned from the bottom
> > to the top.  However I can't work out how to calculate the z
> > coordinate along the scan line that may intersect with a facet.
> >
> > The scanning line is always horizontal and is defined with the
> > x and y coordinates remaining the same, with one end of the line
> > minus z and the other end positive z. As an example at what point
> > does the line whose start point is (54,46,-100) and whose end
> > point is (54,46,100) intersect with a plane facet defined by 4
> > points in a anti-clockwise direction point 1 (40,20,-70),
> > point 2 (40,60,-40), point 3 (120,60,-40) and point 4 (120,20,-70).
> 
> You only need 3 points to define a plane.  Using these three points you
> can calculate the equation for the plane by simulaneous equations.
> ie using the first 3 points the equation using a form of z=mx+ny+b would be:
> 
> 1.  -70 = 40m + 20n + b
> 2.  -40 = 40m + 60n + b
> 3.  -40 = 120m + 60n + b
> 
> Solving these gives m=0,n=0.75,b=-85.
> If you had a more complicated line you could solve the intersection also
> by the same method, however as all x & y values are the same, you can just
> substitute the x & y in, which gives you the intersection at (54,46,-50.5)

Actually, you only need 2 points to define a plane: a point on the plane and
a normal vector. If your line goes from P0 to P1, and Pt is a point on the 
line, then the following equations hold:

    Pt = P0 + t(P1 - P0)    [NOTE: Pt, P1, and P0 are vectors, t is a scalar]

    t < 0 or t > 1 --> no intersection

If Pe is a point on the plane and N is the inside normal to the plane, then 
the following equations hold:

    dot_product( (Pe - Pt), N ) = 0 --> Pt is at the intersection point
                                > 0 --> Pt is inside the plane
                                < 0 --> Pt is outside the plane

        dot_product( N, (Pe - P0) )
    t = ---------------------------
        dot_product( N, (P1 - P0) )

Once you find t, you can find Pt, which is your intersection point. Note that
the equation for t fails if ||N|| = 0 (the 0 vector is usually a bad choice 
for a normal vector :-), if P1 = P0 (no line), or if the line between P1 and P0
is parallel to the plane to which you're clipping (no intersection).

Hope this helps
-Chris
-- 
        \\ || //
        \ .  . /
___.oo0_(__()__)__0oo.___
         
 www.cse.psu.edu/~cclark
Technical Details
Message-ID: <3118310E.52F@psu.edu>
Path: arc1-ca.pugleaf.net!news.cac.psu.edu!usenet
References: <4f3od9$2jg@zeus.tcp.co.uk> <jderrick-0502961551360001@slip037.csc.cuhk.hk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.cac.psu.edu!usenet
From: "Christopher H. Clark" <chc104@psu.edu>
Newsgroups: comp.lang.pascal.borland,comp.lang.pascal.mac,comp.lang.pascal.ansi-iso,comp.lang.pascal.misc,comp.sys.amiga.programmer,comp.graphics.algorithms,comp.os.ms-windows.programmer.graphics,comp.sys.amiga.graphics
Subject: Re: 3d programming
Date: Tue, 06 Feb 1996 23:56:46 -0500
Organization: Penn State
Message-ID: <3118310E.52F@psu.edu>
References: <4f3od9$2jg@zeus.tcp.co.uk> <jderrick-0502961551360001@slip037.csc.cuhk.hk>
NNTP-Posting-Host: chc104.rh.psu.edu
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 2.0b6a (WinNT; I)