POV-Ray : Newsgroups : povray.text.scene-files : A folding paperplane (paperplane.inc) Server Time
1 Nov 2024 05:19:41 EDT (-0400)
  A folding paperplane (paperplane.inc) (Message 1 to 1 of 1)  
From: Nikodemus Siivola
Subject: A folding paperplane (paperplane.inc)
Date: 26 Feb 2001 14:49:41
Message: <3a9ab179.15427961@news.povray.org>
As requested in povray.binaries.animations - just the .inc file,
though.

Basic usage:

Folded model:

	#include "paperplane.inc"

	object { Paperplane
		texture { ... }
	}

Animated (folding) model:

	#declare Paperplane_clock = clock;
	#include "paperplane.inc"

	object { Paperplane
		texture { ... }
	}
		

Yours,

 -- Nikodemus

----8<-----
// paperplane.inc (version 0.3)
// by Nikodemus Siivola
//
// To change defaults:
// #declare Paperplane_controls = array[4] {
//	paper_width, paper_height, center_fold, edge_fold }
//
// To define fold angles:
// #declare Paperplane_fold = array[7] {
//	fold_0, fold_a1, fold_a2, fold_b, fold_c, fold_d, fold_e }
//
// To animate the folding sequence: 
// #declare Paperplane_clock = <clock dependant value>;

#render "\npaperplane.inc by Nikodemus Siivola (version 0.3)\n"

// Control Values
#ifndef (Paperplane_controls)
	#local Paperplane_controls = array[4] { 
		0.13, 0.2, 0.015, 0.0075
	}
	#render "Paperplane_controls undeclared - using defaults.\n"
#end

#local W = Paperplane_controls[0]/2;
#local H = Paperplane_controls[1];
#local C = Paperplane_controls[2];
#local E = Paperplane_controls[3];

// Various secondary values
#local alfa = pi/8;
#local beta = pi/4;
#local L1 = W/tan(alfa);
#local L2 = W*tan(alfa);
#local L3 = C/tan(alfa);
#local L4 = L3;
#local L5 = C/cos(beta);
#local L6 = W-L5;
#local L7 = W+L5;
#local L8 = W-E;
#local L9 = E/tan(alfa); 
#local L10 = L1-L9;
#local L11 = E*tan(beta);
#local L12 = L10+L11;

// Points (vector arrays)
#local pts_M = array[2] {
	<0, 0, 0>,	// Middle point 1
	<0, 0, -H>	// Middle point 2
}
#local pts_C = array[2] {
	<W, 0, 0>,	// Corner pt 1
	<W, 0, -H>	// Corner pt 2
}
#local pts_F = array[13] {
	<0, 0, 0>	// Null point
	<W, 0, -W>,	// Fold pt 1
	<W, 0, -L1>,	// Fold pt 2
	<W, 0, -L2>,	// Fold pt 3
	<C, 0, -L3>,	// Fold pt 4
	<C, 0, -H>,	// Fold pt 5
	<L4, 0, -C>,	// Fold pt 6
	<W, 0, -C>,	// Fold pt 7
	<W, 0, -L6>,	// Fold pt 8
	<W, 0, -L7>,	// Fold pt 9
	<L8, 0, -H>,	// Fold pt 10
	<L8, 0, -L10>,	// Fold pt 11
	<W, 0, -L12>	// Fold pt 12
}

// Folding macros
#macro Fold_along (V, A1, A2, deg)
	vaxis_rotate(V-A1, A2-A1, deg)+A1
#end

#macro Fold_0 (deg)
	#local a1 = pts_M[1];
	#local a2 = pts_M[0];
	#declare pts_C[0] = Fold_along(pts_C[0], a1, a2, deg);
	#declare pts_C[1] = Fold_along(pts_C[1], a1, a2, deg);
	#declare pts_F[1] = Fold_along(pts_F[1], a1, a2, deg);
	#declare pts_F[2] = Fold_along(pts_F[2], a1, a2, deg);
	#declare pts_F[3] = Fold_along(pts_F[3], a1, a2, deg);
	#declare pts_F[4] = Fold_along(pts_F[4], a1, a2, deg);
	#declare pts_F[5] = Fold_along(pts_F[5], a1, a2, deg);
	#declare pts_F[6] = Fold_along(pts_F[6], a1, a2, deg);
	#declare pts_F[7] = Fold_along(pts_F[7], a1, a2, deg);
	#declare pts_F[8] = Fold_along(pts_F[8], a1, a2, deg);
	#declare pts_F[9] = Fold_along(pts_F[9], a1, a2, deg);
	#declare pts_F[10] = Fold_along(pts_F[10], a1, a2, deg);
	#declare pts_F[11] = Fold_along(pts_F[11], a1, a2, deg);
	#declare pts_F[12] = Fold_along(pts_F[12], a1, a2, deg);
#end

#macro Fold_A (deg)
	#local a1 = pts_F[1];
	#local a2 = pts_M[0];
	#declare pts_C[0] = Fold_along(pts_C[0], a1, a2, deg);
	#declare pts_F[3] = Fold_along(pts_F[3], a1, a2, deg);
	#declare pts_F[6] = Fold_along(pts_F[6], a1, a2, deg);
	#declare pts_F[7] = Fold_along(pts_F[7], a1, a2, deg);
	#declare pts_F[8] = Fold_along(pts_F[8], a1, a2, deg);
#end	

#macro Fold_B (deg)
	#local a1 = pts_M[0];
	#local a2 = pts_F[3];
	#declare pts_C[0] = Fold_along(pts_C[0], a1, a2, deg);
	#declare pts_F[7] = Fold_along(pts_F[7], a1, a2, deg);
	#local a1 = pts_F[2];
	#local a2 = pts_M[0];
	#declare pts_C[0] = Fold_along(pts_C[0], a1, a2, deg);
	#declare pts_F[1] = Fold_along(pts_F[1], a1, a2, deg);
	#declare pts_F[3] = Fold_along(pts_F[3], a1, a2, deg);
	#declare pts_F[6] = Fold_along(pts_F[6], a1, a2, deg);
	#declare pts_F[7] = Fold_along(pts_F[7], a1, a2, deg);
	#declare pts_F[8] = Fold_along(pts_F[8], a1, a2, deg);
	#declare pts_F[9] = Fold_along(pts_F[9], a1, a2, deg);
	#declare pts_F[12] = Fold_along(pts_F[12], a1, a2, deg);
#end

#macro Fold_C (deg)
	Fold_0(deg)
#end

#macro Fold_D (deg)
	#local a1 = pts_F[4];
	#local a2 = pts_F[5];
	#declare pts_C[1] = Fold_along(pts_C[1], a1, a2, deg);
	#declare pts_F[2] = Fold_along(pts_F[2], a1, a2, deg);
	#declare pts_F[10] = Fold_along(pts_F[10], a1, a2, deg);
	#declare pts_F[11] = Fold_along(pts_F[11], a1, a2, deg);
	#declare pts_F[12] = Fold_along(pts_F[12], a1, a2, deg);
	#local a1 = pts_F[6];
	#local a2 = pts_F[7];	
	#declare pts_F[3] = Fold_along(pts_F[3], a1, a2, deg);
#end

#macro Fold_E (deg)
	#local a1 = pts_F[10];
	#local a2 = pts_F[11];	
	#declare pts_C[1] = Fold_along(pts_C[1], a1, a2, deg);
	#declare pts_F[2] = Fold_along(pts_F[2], a1, a2, deg);
#end

// Folding controls
#ifndef (Paperplane_fold)
	#local Paperplane_fold = array[7] {
		10,	// Slight crease in the middle of the paper
		175,	// Fold A, stage 1
		5,	// Fold A, stage 2 (add up to 180 w/ stage 1)
		175,	// Fold B
		60,	// Fold C
		58,	// Fold D
		57	// Fold E
	}
	#render "Paperplane_folds undeclared - using defaults.\n"
#end

// Animation system
#ifndef (Paperplane_clock)
	#local Paperplane_clock = 1;
	#render "Paperplane_clock undeclared - using default.\n"
#end

#if (Paperplane_clock<0)
	#local Local_clock = 0;
#else
	#local Local_clock = Paperplane_clock * 5;
#end

#switch (Local_clock)
	#case (0)	// Unfolded
	#break
	#range (0, 1)
		#local Run = Local_clock;
		Fold_0( Run * Paperplane_fold[0] )
		Fold_A( Run * Paperplane_fold[1] )
	#break
	#range (1, 2)
		#local Run = Local_clock-1;
		Fold_0( Paperplane_fold[0] )
		Fold_A( Paperplane_fold[1] )
		Fold_A( Run * Paperplane_fold[2] )
		Fold_B( Run * Paperplane_fold[3] )
	#break
	#range (2, 3)
		#local Run = Local_clock-2;
		Fold_0( Paperplane_fold[0] )
		Fold_A( Paperplane_fold[1] )
		Fold_A( Paperplane_fold[2] )
		Fold_B( Paperplane_fold[3] )
		Fold_C( Run * Paperplane_fold[4] )
	#break
	#range (3, 4)
		#local Run = Local_clock-3;
		Fold_0( Paperplane_fold[0] )
		Fold_A( Paperplane_fold[1] )
		Fold_A( Paperplane_fold[2] )
		Fold_B( Paperplane_fold[3] )
		Fold_C( Paperplane_fold[4] )
		Fold_D( Run * Paperplane_fold[5] )
	#break
	#range (4, 5)
		#local Run = Local_clock-4;
		Fold_0( Paperplane_fold[0] )
		Fold_A( Paperplane_fold[1] )
		Fold_A( Paperplane_fold[2] )
		Fold_B( Paperplane_fold[3] )
		Fold_C( Paperplane_fold[4] )
		Fold_D( Paperplane_fold[5] )
		Fold_E( Run * Paperplane_fold[6] )
	#break
	#else
		Fold_0( Paperplane_fold[0] )
		Fold_A( Paperplane_fold[1] )
		Fold_A( Paperplane_fold[2] )
		Fold_B( Paperplane_fold[3] )
		Fold_C( Paperplane_fold[4] )
		Fold_D( Paperplane_fold[5] )
		Fold_E( Paperplane_fold[6] )
#end

// Some co limits to stop the paper form "tearing"
#if (pts_C[0].x<0)
	#local pts_C[0] = <0, pts_C[0].y, pts_C[0].z>;
#end
#if (pts_F[1].x<0)
	#local pts_F[1] = <0, pts_F[1].y, pts_F[1].z>;
#end

// The Paper (one half)
#local Paper = mesh {
	// Area 1
	triangle { pts_M[0], pts_C[0], pts_F[6] }
	triangle { pts_F[6], pts_C[0], pts_F[7] }
	// Area 2
	triangle { pts_F[6], pts_F[7], pts_F[3] }
	// Area 3
	triangle { pts_F[6], pts_F[3], pts_F[8] }
	// Area 4
	triangle { pts_M[0], pts_F[6], pts_F[1] }
	triangle { pts_F[6], pts_F[8], pts_F[1] }
	// Area 5
	triangle { pts_M[0], pts_F[4], pts_F[1] }
	triangle { pts_F[4], pts_F[1], pts_F[9] }
	// Area 6
	triangle { pts_F[9], pts_F[11], pts_F[4] }
	triangle { pts_F[9], pts_F[11], pts_F[12] }
	// Area 7
	triangle { pts_M[0], pts_F[4], pts_M[1] }
	triangle { pts_F[4], pts_M[1], pts_F[5] }
	// Area 8
	triangle { pts_F[11], pts_F[2], pts_C[1] }
	triangle { pts_F[11], pts_F[10], pts_C[1] }
	// Area 9
	triangle { pts_F[11], pts_F[12], pts_F[2] }
	// Area 10
	triangle { pts_F[4], pts_F[11], pts_F[5] }
	triangle { pts_F[11], pts_F[5], pts_F[10] }
}

#declare Paperplane = union {
	object { Paper }
	object { Paper scale <-1, 1, 1> }
	translate <0, 0, H/2>
}


Post a reply to this message

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