POV-Ray : Newsgroups : povray.text.scene-files : Star polygon macro Server Time
31 Oct 2024 14:08:56 EDT (-0400)
  Star polygon macro (Message 1 to 2 of 2)  
From: Russell Towle
Subject: Star polygon macro
Date: 23 Mar 2008 14:15:01
Message: <web.47e6aaf1cf79a0e2b558e56e0@news.povray.org>
I wrote a star polygon macro which puts spheres on the vertices and cylinders on
the edges.

First, a scene file which uses the macro; and below it, the macro itself.

//begin scene file
/*
Star Polygons, by Russell Towle, March 2008.
email: Russell Towle <rus### [at] gmailcom>

Star Polygons: With two user-defined parameters, N and S,
we may create a variety of both regular convex polygons and regular star
polygons,
and also, compounds of regular polygons,
with cylinders on their sides and spheres on their edges.
The radii of the spheres (R1) and cylinders (R2) may be set independently.
Star polygons get "pointier" as S approaches N/2.

The macro syntax is: starpolygon (N, S, R1, R2)
The four user-defined parameters are listed below:
1.  N, the number of vertices and sides; N>=3. Example: N=12.
2.  S, how many vertices to step,S<N/2. Example: S=5.
3.  R1, radius of spheres. Example: .1
4.  R2, radius of cylinders. Example: .05
*/

#version 3.6
#include "textures.inc"
#include "starmacro.mcr"//call macro
#default { texture { pigment {rgb 1} finish{ ambient 0.2 diffuse 0.6 } }}

camera {
 location <0, 3, -.5>
 look_at 0
}

light_source {<5, 15, -5> color rgb <1, 1, 1>}

//T1 is sphere texture, T2, cylinder texture
#declare T1 = texture{Gold_Metal};
#declare T2 = texture{Silver_Metal};

starpolygon (12, 5, .1, .05)

plane { y, -.2 }
//end scene file
/**********/

//begin macro; save as "starmacro.mcr"
/*Star Polygon macro, by Russell Towle, March 2008.*/

#ifndef(T1)
#declare T1 = texture{Gold_Metal}
#end

#ifndef(T2)
#declare T2 = texture{Silver_Metal}
#end

#macro starpolygon (N, S, R1, R2)
union{ //begin union
#local J = 1; //initialize loop
#while (J <= N) //begin loop
#local A = <cos(J*2*pi/N), 0, sin(J*2*pi/N)>;
#local B = <cos((J+S)*2*pi/N), 0, sin((J+S)*2*pi/N)>;

sphere{A, R1 texture{T1}} //spheres on vertices
cylinder{A, B, R2 texture{T2}} //cylinders on edges

#local J = J+1; //increment loop
#end //end loop
} // end union
#end
//end macro


Post a reply to this message

From: Dave VanHorn
Subject: Re: Star polygon macro
Date: 21 Oct 2008 18:20:01
Message: <web.48fe547d2803bc41a08ed15e0@news.povray.org>
"Russell Towle" <rto### [at] inreachcom> wrote:
> I wrote a star polygon macro which puts spheres on the vertices and cylinders on
> the edges.



Is this Russell Towle from Dutch Flat? :)

Thanks for doing this, I was looking for exactly this for a scene I'm working
on.


Post a reply to this message

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