POV-Ray : Newsgroups : povray.programming : Bicubic patch bug (job000202) Server Time
28 Jul 2024 08:30:56 EDT (-0400)
  Bicubic patch bug (job000202) (Message 1 to 5 of 5)  
From: Massimo Valentini
Subject: Bicubic patch bug (job000202)
Date: 21 Oct 2002 12:34:04
Message: <3db42c7c@news.povray.org>
This bug (http://news.povray.org/3c23b26c@news.povray.org) is a simple 
scaling problem.

In the file bezier.cpp there are three cross products (VCross) and
after each one you check the squared length of the resulting vector 
against BEZIER_EPSILON (1.0e-10). 
But the result of a cross product (a = b x c) is a vector (a) whose 
length is the product of the length of the two vectors times the sine 
of the angle.

||a|| = ||b|| ||c|| sin(b^c).  

so scaling b and c, as the bug report author does, there is  a value
of the scaling factor, below which a condition like

||a||^2 > BEZIER_EPSILON

is no more satisfied. It suffices to transform the three conditions
to:

||a||^2 > BEZIER_EPSILON * ||b||^2 * ||c||^2

and the image produced is quite independent from the scale factor.

HTH Massimo


Post a reply to this message

From: Safari
Subject: Re: Bicubic patch bug (job000202)
Date: 5 Nov 2002 10:51:05
Message: <slrnasfq79.2b8.y7pt9001@safari.homelinux.net>
On Mon, 21 Oct 2002 18:27:19 +0200,
Massimo Valentini <six### [at] inwindit> wrote:
...
> so scaling b and c, as the bug report author does, there is  a value
> of the scaling factor, below which a condition like
> 
>||a||^2 > BEZIER_EPSILON
> 
> is no more satisfied. It suffices to transform the three conditions
> to:
> 
>||a||^2 > BEZIER_EPSILON * ||b||^2 * ||c||^2
> 
> and the image produced is quite independent from the scale factor.
> 
> HTH Massimo

hmm..  can you provide patch against povray-3.50 bezier.cpp?

-- 
Safari - y7p### [at] sneakemailcom
"Talk is cheap. Show me the code." - Linus Torvalds


Post a reply to this message

From: Massimo Valentini
Subject: Re: Bicubic patch bug (job000202)
Date: 5 Nov 2002 12:14:41
Message: <3dc7fc81@news.povray.org>
"Safari" ha scritto 
: > 
: >||a||^2 > BEZIER_EPSILON * ||b||^2 * ||c||^2
: > 
: > and the image produced is quite independent from the scale factor.
: > 
: > HTH Massimo
: 
: hmm..  can you provide patch against povray-3.50 bezier.cpp?
: 

Here it is.

Massimo

--- src/bezier.cpp.ex Tue Nov  5 17:44:32 2002
+++ src/bezier.cpp Tue Nov  5 17:44:32 2002
@@ -469,7 +469,9 @@
   
   VDot(t, N, N);
   
-  if (t > BEZIER_EPSILON)
+  DBL squared_u1 = VSumSqr(U1);
+  DBL squared_v1 = VSumSqr(V1);
+  if (t > BEZIER_EPSILON * squared_u1 * squared_v1)
   {
     t = 1.0 / sqrt(t);
     
@@ -520,9 +522,11 @@
 
   VCross(Result, V1, V2);
 
-  VLength(Length, Result);
+  Length = VSumSqr(Result);
+  DBL squared_v1 = VSumSqr(V1);
+  DBL squared_v2 = VSumSqr(V2);
 
-  if (Length < BEZIER_EPSILON)
+  if (Length <= BEZIER_EPSILON * squared_v1 * squared_v2)
   {
     Make_Vector(Result, 1.0, 0.0, 0.0);
 
@@ -532,6 +536,8 @@
   }
   else
   {
+    Length = sqrt(Length);
+   
     VInverseScale(Result, Result, Length);
 
     VDot(*d, Result, v1);
@@ -581,7 +587,9 @@
 
   VDot(d, B[2], B[2]);
 
-  if (d < BEZIER_EPSILON)
+  DBL squared_b0 = VSumSqr(B[0]);
+  DBL squared_b1 = VSumSqr(B[1]);
+  if (d <= BEZIER_EPSILON * squared_b1 * squared_b0)
   {
     return (0);
   }


Post a reply to this message

From: Gleb
Subject: Re: Bicubic patch bug (job000202)
Date: 8 Nov 2002 12:04:11
Message: <3dcbee8b@news.povray.org>
Unfortunately, this patch is not enough, at least in some cases.
For the moment I am using brute force:
#define BEZIER_EPSILON 1.0e-20
in original povray-3.50 bezier.cpp,

but it should be a better way to cure this,
I'm not sure that this will always work.

Check this code for example, it works almost the same way
both with povray-3.50 and with your patch,
only with BEZIER_EPSILON=1.0e-20 it is OK.

Gleb

//----------------8<----------------
//640x480 AA 0.3

camera {
  location y-x-z
  look_at 0
}

#declare Object=
bicubic_patch{type 1 flatness 0 u_steps 4 v_steps 4
<-24.54,61.83,-41.23><-22.71,63.03,-43.12><-18.35,63.7,-45.4><-15.8,60.14,-4
4.2>
<-24.54,59.08,-52.08><-22.39,61.24,-51.29><-17.66,59.73,-60.16><-15.86,57.59
,-57.03>
<-10.85,58.23,-66.27><-12.70,60.62,-71.79><-6.52,53.89,-76.18><-9.01,51.02,-
77.93>
<0,55.05,-63.27><0,57.61,-70.18><0,54.61,-75.95><0,52.51,-77.30>
}


#declare Object=#object{Object
  #local vv=-(max_extent(Object)-min_extent(Object))/2;
  translate vv-min_extent(Object)
  scale .75/vlength(vv)
}

#object{Object
  scale 1/16
  pigment{color rgb 1}
  finish{ ambient 10}
}
//----------------8<----------------


Post a reply to this message

From: Massimo Valentini
Subject: Re: Bicubic patch bug (job000202)
Date: 8 Nov 2002 14:04:59
Message: <3dcc0adb@news.povray.org>
"Gleb" ha scritto 
: Unfortunately, this patch is not enough, at least in some cases.
: For the moment I am using brute force:
: #define BEZIER_EPSILON 1.0e-20
: in original povray-3.50 bezier.cpp,
: 
: but it should be a better way to cure this,
: I'm not sure that this will always work.
: 
: Check this code for example, it works almost the same way
: both with povray-3.50 and with your patch,
: only with BEZIER_EPSILON=1.0e-20 it is OK.
: 

Unfortunately, I'm not able to reproduce your report:

If I render your scene, that I reconstructed (some lines has been
broken), with the orignal bezier.cpp I obtain a little white spot
at the center of a black image. If I change the #define 
BEZIER_EPSILON to 1.0e-20, I see a little white surface (white 
butterfly?) in the same place, and this is the exact same image 
I obtain patching the original bezier.cpp with the patch that is 
in my previous message. 

Massimo


Post a reply to this message

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