POV-Ray : Newsgroups : povray.general : 'flatten' a polygon : 'flatten' a polygon Server Time
23 Apr 2024 15:59:12 EDT (-0400)
  'flatten' a polygon  
From: ingo
Date: 9 Feb 2019 12:15:12
Message: <XnsA9F1B9AEA58B3seed7@news.povray.org>
Quite often I run ito the problem that polygons won't render because not 
all the points are on the same plane. Today I figured out how to fix 
that, scene below, but is there a more efficient way?


---%<------%<------%<---
#version 3.7;
global_settings{ assumed_gamma 1.0 }
#default{ finish{ ambient 0.1 diffuse 0.9 }} 
#include "math.inc"
#include "transforms.inc"

camera {
  perspective angle 5
  location  <0 , 10 ,-10>
  look_at   <0,0,0>
}
light_source{< 500,3000,-500> rgb 1}
light_source{<-3000,3000,-3000> rgb .5}

#declare Point=array[6]{
  <0.429381,-0.055167, 0.379816>,
  <0.516580,-0.092380, 0.240426>,
  <0.291647,-0.556033,-0.000017>,
  <0.185583,-0.627011, 0.044906>,
  <0.097999,-0.570008, 0.205955>,
  <0.172851,-0.214639, 0.501546>,
};
#declare Normal = <0.614179,-0.577098,0.538277>;

// distance from the first point to the plane
#declare Distance = vdot(Normal,Point[0]);
#declare T = transform{translate Normal*Distance}; 
#for(I,0,dimension_size(Point,1)-1,1)
  // push the points to the aligned plane
  #declare Point[I] = VProject_Plane(Point[I], Normal);
  // translate them to their 'original' positions
  #declare Point[I] = vtransform(Point[I], T);
#end

polygon{
  7,
  Point[0]
  Point[1]
  Point[2]
  Point[3]
  Point[4]
  Point[5]
  Point[0]
  pigment{rgb 1}
}
sphere{0,0.01 pigment{rgb x}}


Post a reply to this message

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