POV-Ray : Newsgroups : povray.general : 'flatten' a polygon Server Time
21 Dec 2024 21:01:34 EST (-0500)
  'flatten' a polygon (Message 1 to 6 of 6)  
From: ingo
Subject: 'flatten' a polygon
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

From: Alain
Subject: Re: 'flatten' a polygon
Date: 10 Feb 2019 14:52:44
Message: <5c60810c$1@news.povray.org>
Le 19-02-09 à 12:15, ingo a écrit :
> 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}}
> 

If you create your polygon on the X-Y plane, you won't have any problem. 
Then, it's just a mater of rotating it as needed :

#declare Point=array[6]{
   <0.429381,-0.055167>,
   <0.516580,-0.092380>,
   <0.291647,-0.556033>,
   <0.185583,-0.627011>,
   <0.097999,-0.570008>,
   <0.172851,-0.214639>,
};

polygon{
   7,
   Point[0]
   Point[1]
   Point[2]
   Point[3]
   Point[4]
   Point[5]
   Point[0]
   pigment{rgb 1}
   rotate Some_Rotation
}


Post a reply to this message

From: ingo
Subject: Re: 'flatten' a polygon
Date: 10 Feb 2019 16:59:10
Message: <XnsA9F2E9D3D4F15seed7@news.povray.org>
in news:5c60810c$1@news.povray.org Alain wrote:

> If you create your polygon on the X-Y plane

Should have added that the points are generated externaly and have 3 
coordinates,

merci Alain,

ingo


Post a reply to this message

From: Leroy
Subject: Re: 'flatten' a polygon
Date: 16 Feb 2019 17:10:01
Message: <web.5c68897fc4e92e71738950420@news.povray.org>
Quite interesting Polygons in a plane that's not on the z plane.
I've haven't played with polygons for a long time.
What you've done looks good, but you'll like to do better(fast).
Give me awhile to play with this new toy and see what I can see.


Post a reply to this message

From: Leroy
Subject: Re: 'flatten' a polygon
Date: 17 Feb 2019 18:15:00
Message: <web.5c69ea83c4e92e71ac15978b0@news.povray.org>
I've come up with something which maybe faster.
The main idea behind this is that you only change the points you have to.

Here it is:

// Vers: 3.7
// Auth: Leroy Whetstone
// Email whe### [at] gmailcom
// Translate  polygon,normal data to POV polygon
//====================================================================
#version 3.7;
#include "colors.inc"
#include "math.inc"
global_settings {assumed_gamma 1 max_trace_level 20}

camera{ location <-3,3,-3>
        look_at <0,0,0>
        right x*image_width/image_height
        }
 light_source{<0,10,0> color White}
 light_source{<0,0,-10> color White}


//---------- Test Data --------------------
#declare
Data=array[11]{<-0.32,0.32,0>,<-0.12,0.386667,0>,<0.0933333,0.28,0>,<0.16,-0.0266667,0>,

<0.266667,-0.213333,0>,<0.2,-0.32,0>,<0.0666667,-0.266667,0>,

<-0.0133333,-0.346667,0>,<-0.16,-0.12,0>,<-0.32,0.0666667,0>,
                        <-0.32,0.32,0>}

#declare Norm=-z;

#declare TestR=<95,30,10>; // test rotate

// --------- move test points --------------------
#for(a,0,10)
  #declare Data[a]=vrotate(Data[a],TestR)-2*x+y;
#end
#declare Norm=vrotate(Norm,TestR);

  #declare Data[5]=Data[5]+x*.0001;

// ----------------get plane----------------
#macro SetPlane()
 #local V=Norm;
 #declare Cp= (Data[0]+Data[1]+Data[2])/3;// center point of triangle data 0,1,2
 #local V1=vnormalize(Cp);
 #if((V1.x=V.x)&(V1.x=V.y)&(V1.x=V.y))
   #local D= vlength(Cp);
 #else
   #local Ag=VAngle(Cp,V);
   #local D= vlength(Cp)*cos(Ag);
 #end
 #declare K=D*sqrt(V.x*V.x + V.y*V.y + V.z*V.z);//keep part of plane equation
#end

#macro Test(T)
 #local O=Norm.x*T.x + Norm.y*T.y + Norm.z*T.z -K ;//test on plane ?
 O
#end

//Test and Fix Data
 SetPlane();
#for(a,0,10)
  #declare B=Test(Data[a]);//if B=0 point is on plane
  #if(B) #debug concat("A =",str(a,0,0)," B=",str(B,9,9),"\n")
  #declare Data[a]=VProject_Plane(Data[a]-Cp, Norm)+Cp; // fix broken data
  #end
#end

// origonal polygon rotate and move to veiw
polygon{
11
<-0.32,0.32>
<-0.12,0.386667>
<0.0933333,0.28>
<0.16,-0.0266667>
<0.266667,-0.213333>
<0.2,-0.32>
<0.0666667,-0.266667>
<-0.0133333,-0.346667>
<-0.16,-0.12>
<-0.32,0.0666667>
<-0.32,0.32>
rotate TestR
pigment{Red}
translate x*2
}

// test polygon
polygon{
 11
 #for(a,0,10)
  Data[a]
 #end
 pigment{Red}
}


 #for(a,0,10)
  #debug concat("Data[",str(a,0,0),"] = <",vstr(3,Data[a] ,",",3,3),">\n")
 #end


Have Fun!


Post a reply to this message

From: ingo
Subject: Re: 'flatten' a polygon
Date: 18 Feb 2019 02:06:02
Message: <XnsA9FA5268137B3seed7@news.povray.org>
in news:web.5c69ea83c4e92e71ac15978b0@news.povray.org Leroy wrote:

> Have Fun!
> 
> 

I'll have a poke at it Leroy, thanks,

ingo


Post a reply to this message

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