POV-Ray : Newsgroups : povray.advanced-users : 3D mathematics question Server Time
28 Jul 2024 20:21:52 EDT (-0400)
  3D mathematics question (Message 9 to 18 of 18)  
<<< Previous 8 Messages Goto Initial 10 Messages
From: Andrew the Orchid
Subject: Re: 3D mathematics question
Date: 8 Nov 2004 17:22:58
Message: <418ff1c2$1@news.povray.org>
#macro TestIsect(A, B, C, P, Q)
   #local AB = B - A;
   #local AC = C - A;
   #local N = vcross(AB, AC);

   #local PQ = Q - P;

   #local _t = vdot(N, A - P) / vdot(N, PQ);

   #local Isect = ((_t >= 0) & (_t <= 1));

   #if (Isect)
     #local I = P + PQ*_t;

     #local AI = I - A;
     #local J = vcross(N, AB);
     #local K = vcross(N, AC);
     #local _u = vdot(AI, K) / vdot(AB, K);
     #local _v = vdot(AI, J) / vdot(AC, J);

     #local Isect = ((_u >= 0) & (_v >= 0) & (_u + _v <= 1));
   #end

   Isect
#end

Andrew.

PS. Annoying that I have to put the underscores on those variable 
names... grrr!


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: 3D mathematics question
Date: 8 Nov 2004 17:38:29
Message: <418ff565$1@news.povray.org>
Andrew the Orchid wrote:
>> Inverse trigonometric operations are slow.
>>
>> Try this search:
>>
>> http://www.google.com/search?q=efficient+line+triangle+intersection
> 
> 
> Was about to try something even more complex and longwinded. But the 
> very first link gives me this:
> 
> Plane thru A, B, C is given by
>   P(u, v) = A + u*AB + v*AC
> Line thru J, K is given by
>   L(t) = J + t*JK
> Intersection of P and L is I=L(t) where
>   t = N . (A - P) / N . (Q - P)
> u,v coordinate of I is
>   u = AI . (N x AC) / AB . (N x AC)
>   v = AI . (N x AB) / AC . (N x AB)
> (N = normal of the plane).
> 
> Finally, the point lies within the triangle iff
>   u >= 0
>   v >= 0
>   u+v <= 1
> 
> Add to that a check in case the line and triangle are perpendicular - 
> and anoter check because I want my line to be finite length (check that 
> 0<=t<=1) and we're done! Ha!

Yes that looks elegant.

When I sit down and figure out such things myself,
I continue until the solution is as simple as I
can manage to make it.

If it then does not look elegant, then it's probably
not the best solution.

-- 
Tor Olav
http://subcube.net
http://subcube.com


Post a reply to this message

From: Alain
Subject: Re: 3D mathematics question
Date: 8 Nov 2004 17:59:35
Message: <418ffa57$1@news.povray.org>
Andrew the Orchid nous apporta ses lumieres ainsi en ce 2004-11-08 
17:22... :

>
>
> Andrew.
>
> PS. Annoying that I have to put the underscores on those variable 
> names... grrr!

Use Upercase then you don't need those underscores.


Post a reply to this message

From: Christopher James Huff
Subject: Re: 3D mathematics question
Date: 8 Nov 2004 23:34:44
Message: <cjameshuff-44B729.23344508112004@news.povray.org>
In article <418fe747$1@news.povray.org>,
 Tor Olav Kristensen <tor### [at] TOBEREMOVEDgmailcom> wrote:

> Inverse trigonometric operations are slow.

In POV, the difference between an inverse trig operation and any other 
operation is likely to be overwhelmed by the overhead of parsing the 
script. Code that is simpler to parse is likely to be faster.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: 3D mathematics question
Date: 9 Nov 2004 07:55:40
Message: <4190be4c$1@news.povray.org>
Christopher James Huff wrote:
> In article <418fe747$1@news.povray.org>,
>  Tor Olav Kristensen <tor### [at] TOBEREMOVEDgmailcom> wrote:
> 
> 
>>Inverse trigonometric operations are slow.
> 
> 
> In POV, the difference between an inverse trig operation and any other 
> operation is likely to be overwhelmed by the overhead of parsing the 
> script. Code that is simpler to parse is likely to be faster.

Yes, I know.

I thought it was a general mathematic question.

-- 
Tor Olav
http://subcube.net
http://subcube.com


Post a reply to this message

From: Andrew the Orchid
Subject: Re: 3D mathematics question
Date: 9 Nov 2004 15:14:51
Message: <4191253b$1@news.povray.org>
>> PS. Annoying that I have to put the underscores on those variable 
>> names... grrr!
> 
> 
> Use Upercase then you don't need those underscores.

The idea is to use upercase for vectors and lowercase for scalars...

But yes, that would also work of course.

Andrew.

(I understand not being able to use "x", "y" and "z", but "t"? That's 
not even *valid* as a token by itself...)

Also vaguely irritating is the need to wrap Boolean assignments with 
brackets, but still...


Post a reply to this message

From: ABX
Subject: Re: 3D mathematics question
Date: 9 Nov 2004 15:21:09
Message: <3j92p01fa2rf6oc4vj9g6t9h3g54id0c83@4ax.com>
On Tue, 09 Nov 2004 20:14:17 +0000, Andrew the Orchid <voi### [at] devnull> wrote:
> (I understand not being able to use "x", "y" and "z", but "t"? That's 
> not even *valid* as a token by itself...)

http://www.povray.org/documentation/view/3.6.1/229/

  VECTOR_BUILT-IN_IDENT:
       x | y | z | t | u | v

and later

  2.2.1.4.3 Operators

and then try

#declare V=<1,2,3,4>;
#declare Vt=V.t;

ABX


Post a reply to this message

From: Andrew the Orchid
Subject: Re: 3D mathematics question
Date: 9 Nov 2004 15:22:52
Message: <4191271c@news.povray.org>
>>(I understand not being able to use "x", "y" and "z", but "t"? That's 
>>not even *valid* as a token by itself...)
> 
> 
> http://www.povray.org/documentation/view/3.6.1/229/
> 
>   VECTOR_BUILT-IN_IDENT:
>        x | y | z | t | u | v
> 
> and later
> 
>   2.2.1.4.3 Operators
> 
> and then try
> 
> #declare V=<1,2,3,4>;
> #declare Vt=V.t;

Oh, sure... V.t is a perfectly valid expression. But - unlike "x" / "y" 
/ "z", "t" by itself isn't a valid expression.


Post a reply to this message

From: ABX
Subject: Re: 3D mathematics question
Date: 9 Nov 2004 15:29:12
Message: <2s92p0hivb564ku67h24vehqqnn6u6qi74@4ax.com>
On Tue, 09 Nov 2004 20:22:17 +0000, Andrew the Orchid <voi### [at] devnull> wrote:
> Oh, sure... V.t is a perfectly valid expression. But - unlike "x" / "y" 
> / "z", "t" by itself isn't a valid expression.

Look later into "2.2.1.4.6 Built-in Constants"

All built-in vector identifiers never change value. They are defined as though
the following lines were at the start of every scene. 

 #declare x = <1, 0, 0>;
 #declare y = <0, 1, 0>;
 #declare z = <0, 0, 1>;
 #declare t = <0, 0, 0, 1>;
 #declare u = <1, 0>;
 #declare v = <0, 1>;

ABX


Post a reply to this message

From: Andrew the Orchid
Subject: Re: 3D mathematics question
Date: 9 Nov 2004 15:42:35
Message: <41912bbb$1@news.povray.org>
>  #declare t = <0, 0, 0, 1>;
>  #declare u = <1, 0>;
>  #declare v = <0, 1>;

Well... you learn something every day... I never knew you could do that...


Post a reply to this message

<<< Previous 8 Messages Goto Initial 10 Messages

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.