From: "Dave Eberly" Subject: Re: point inside a tri, z value? Date: 03 Nov 1999 00:00:00 GMT Message-ID: <7vqksm\$gum\$1@nntp2.atl.mindspring.net> References: <7vqjep\$57i\$1@newssvr04-int.news.prodigy.com> X-Priority: 3 X-Server-Date: 4 Nov 1999 00:44:06 GMT X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Organization: Magic Software X-MSMail-Priority: Normal Newsgroups: comp.graphics.algorithms Doug wrote in message news:7vqjep\$57i\$1@newssvr04-int.news.prodigy.com... > I have a 3 vectors forming a triangle transformed to screen space. X,Y = > pixel positions and Z for the zbuffer. > > How do I calc a Z value from the triangle's Z values for any x,y point > inside the triangle? Let the points be (x0,y0,z0), (x1,y1,z1), (x2,y2,z2). Given (x,y), solve for s and t in (x,y) = (x0,y0)+s*(x1-x0,y1-y0)+t*(x2-x0,y2-y0). The point is inside the triangle if s >= 0, t >= 0, and s+t <= 1. Then choose z = (1-s-t)*z0+s*z1+t*z2. -- Dave Eberly eberly@magic-software.com http://www.magic-software.com