POV-Ray : Newsgroups : povray.general : Math problem : Re: Math problem Server Time
2 Aug 2024 04:23:30 EDT (-0400)
  Re: Math problem  
From: Tor Olav Kristensen
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

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