POV-Ray : Newsgroups : povray.general : Math problem Server Time
1 Nov 2024 03:16:01 EDT (-0400)
  Math problem (Message 1 to 4 of 4)  
From: Shark
Subject: Math problem
Date: 22 Jan 2005 16:55:01
Message: <web.41f2cabdefa74e37fec401a20@news.povray.org>
In POVray, how do you calculate the intersection of two lines given a point
on each line and their vectors?
Is there a handy include file somewhere with a macro that does this?

Thanks,
Shark


Post a reply to this message

From: Mike Williams
Subject: Re: Math problem
Date: 23 Jan 2005 02:44:47
Message: <XyEGTAAcW18BFwPl@econym.demon.co.uk>
Wasn't it Shark who wrote:
>In POVray, how do you calculate the intersection of two lines given a point
>on each line and their vectors?
>Is there a handy include file somewhere with a macro that does this?

You could declare (but not render) an extremely thin cylinder around one
of the lines and then use trace().

In most cases there would be no intersection, so do remember to check
for failures.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Math problem
Date: 23 Jan 2005 07:27:34
Message: <41f39836$1@news.povray.org>
Shark wrote:
> In POVray, how do you calculate the intersection of two lines given a point
> on each line and their vectors?
> Is there a handy include file somewhere with a macro that does this?

Below are some old macros I once made.
(I don't have time to check if they still work.)


Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright Tor Olav Kristensen
// http://subcube.com
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

// Projection of the vector v1 in the direction  of the vector v2.

#macro vproject(v1, v2)

   (v2*vdot(v1, v2)/vdot(v2, v2))

#end // macro vproject


#macro inv_vproject(v1, v2)

   (v2/vdot(v2, v1)*vdot(v1, v1))

#end // macro inv_vproject


// Find the two points on the lines which is closest to each other

#macro ln2ln(pLine1, vLine1, pLine2, vLine2, p1, p2)

   #local vPN = pLine2 - pLine1;
   #local vPQ = vPN - vproject(vPN, vcross(vLine1, vLine2));
   #local vQS = inv_vproject(vproject(vPQ, vLine1) - vPQ, vLine2);

   #declare p1 = pLine1 + vQS + vPQ;
   #declare p2 = pLine2 + vQS;

#end // macro ln2ln

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

From: Shark
Subject: Re: Math problem
Date: 5 Feb 2005 16:10:00
Message: <web.420534fe8c1600b8fec401a20@news.povray.org>
Tor Olav Kristensen <tor### [at] TOBEREMOVEDgmailcom> wrote:
> Shark wrote:
> > In POVray, how do you calculate the intersection of two lines given a point
> > on each line and their vectors?
> > Is there a handy include file somewhere with a macro that does this?
>
> Below are some old macros I once made.
> (I don't have time to check if they still work.)

Yes, these worked splendidly! Thanks!

Shark


Post a reply to this message

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