POV-Ray : Newsgroups : povray.general : queston for the math wizards... : Re: queston for the math wizards... Server Time
6 Aug 2024 00:17:11 EDT (-0400)
  Re: queston for the math wizards...  
From: Tor Olav Kristensen
Date: 12 Jul 2002 20:06:51
Message: <3D2F6D9F.8230FC9D@hotmail.com>
Dan Byers wrote:
> 
> http://hometown.aol.com/goofygrafx/qa.html
> 
> I'd post the question and associated images here, but last time I posted a
> binary file in this NG I got verbally slapped about.  Anyway, any help is
> appreciated.

Dan,

I think the PlaneToLineSegment() macro in the code below will
solve your problem. The rest of the code illustrates the problem
and shows the solution.

The macro can solve a more general problem in 3D space too.
(See comment above macro.)

I do not really understand why the colors of the cylinder grid
"shines through" in some regions. Can anyone explain this ?


Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2002 by Tor Olav Kristensen
// Email: t o r _ o l a v _ k [ a t ] h o t m a i l . c o m
// http://hjem.sol.no/t-o-k/povray
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.5;

#include "colors.inc"

default { texture { finish { ambient White*0.8 } } }

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

background { color Gray30 }

camera {
  orthographic
  location 5*x + 5*y - 10*z
}


// Show coordinate grid

union {
  #local Cnt = 0;
  #while (Cnt <= 10)
    cylinder { 0*x, 10*x, 0.03 translate Cnt*y }
    cylinder { 0*y, 10*y, 0.03 translate Cnt*x }
    #local Cnt = Cnt + 1;
  #end // while
  pigment { color Yellow } 
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Macro to find the closest point in a line segment to a plane

#macro PlaneToLineSegment(pPlane, vPlane, p1Line, p2Line)

  #local vLine = p2Line - p1Line;
  #local S = vdot(pPlane - p1Line, vPlane)/vdot(vLine, vPlane);

  (p1Line + max(0, min(S, 1))*vLine)

#end // macro PlaneToLineSegment


#declare HLT = 0.08; // Half of the line thickness


// Define a line segment

#declare pA = 2*x + 2*y;
#declare pB = 6*x + 7*y;

union {
  cylinder { pA, pB, HLT }
  sphere { pA, HLT*2 }
  sphere { pB, HLT*2 }
  pigment { color Red }
}


// Define another "line"

#declare pPl = y*5; // A point in plane
#declare vPl = y; // A normal vector for plane
//#declare vPl = vPl + x/5; // Make it a different "line"

union {
  cylinder {
    -vPl*HLT, vPl*HLT, 12
    translate pPl
  }
  sphere { pPl, HLT*2 }
  pigment { color Magenta/2 + Blue/3 }
}


// Find intersection of line segment and other "line"

#declare pIntersect = PlaneToLineSegment(pPl, vPl, pA, pB);

sphere { pIntersect, HLT*2.5 pigment { color White*2 } }

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


Post a reply to this message

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