POV-Ray : Newsgroups : povray.general : Perpendicular to an arbitrary axis : Re: Perpendicular to an arbitrary axis Server Time
2 Aug 2024 20:22:40 EDT (-0400)
  Re: Perpendicular to an arbitrary axis  
From: Tor Olav Kristensen
Date: 2 Aug 2004 20:32:37
Message: <410edd25$1@news.povray.org>
Rick Measham wrote:
> Thanks to those who helped last week when I needed to find a point on an
> arbitrary axis between two points. The vnormalize has worked brilliantly.
> 
> Now I come to beg more wisdom from you.
> 
> Lets say there's two points: l_source and l_point_at. Last weeks question
> gave me l_desitination which is a point on the axis between those two. I've
> drawn a cylinder there with a matchine sphere at l_source.
> 
> I've hollowed the object and now need to punch some holes around the edge.
> These holes have a focal point around the l_source and need to be angled
> along the same axis as the cylinder. After learning about vnormalize I went
> looking and found a couple of other v___ funtions. Hobbling them together I
> got the following:
> 
>   union {
>    // Put vent holes around the source
>    #local x_point = vcross(l_source, l_point_at); // get a perpendicular
>    #declare loop_index = 1;
>    #while (loop_index <= hole_count)
>     #local x_point = vaxis_rotate(x_point, vnormalize(l_source -
> l_point_at), 360/hole_count);
>     cylinder {
>      <0,0,0>
>      x_point
>      snoot_radius / 20
>      translate l_source
>      pigment { Yellow }
>     }
>     #declare loop_index = loop_index + 1;
>    #end
>   }
> 
> Amazingly this works! Almost.
> 
> When l_point_at is <0,0,0> or some point along the path between l_source and
> <0,0,0> I get a parse error:
> Parse Error: Degenerate cylinder, base point = apex point.
> 
> I figure it's going to be as easy as extending something a little bit in
> some direction somewhere. But where? Help me, O Learned Ones.

The code below should work.

I recommend that you read this section in the manual:

http://www.povray.org/documentation/view/3.6.0/49/
(2.1.2.2.2 #declare vs. #local)

- if you haven't already done so.


Tor Olav


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

#version 3.6;

#include "colors.inc"
#include "math.inc" // For the VPerp_To_Vector() macro

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Set known constants

#declare NrOfHoles = 6;
#declare CylinderRadius = 0.6;
#declare HolesRadius = 0.2;
#declare pSource = <-3, -2, -2>;
#declare pPointAt = <3, 2, 3>;
#declare DistFromSource = 1.5;

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

#declare vDir = pPointAt - pSource;
#declare vPerp = VPerp_To_Vector(vDir);

difference {
   cylinder {
     pSource, pPointAt, CylinderRadius
     pigment { color Yellow }
   }
   #declare Cnt = 0;
   #while (Cnt < NrOfHoles)
     #declare pAround = vaxis_rotate(vPerp, vDir, Cnt/NrOfHoles*360);
     cylinder {
       <0, 0, 0>, pAround, HolesRadius
       translate pSource + DistFromSource*vnormalize(vDir)
       pigment { color Red*2 }
     }
     #declare Cnt = Cnt + 1;
   #end
}

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

light_source { <3, 6, -4>*10 color White }

camera {
   location <0, 1, -3>*3
   look_at <0, 0, 0>
}

background { color Grey }

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


Post a reply to this message

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