POV-Ray : Newsgroups : povray.general : Is this a bug? (Or am I not seeing something obvious) Server Time
26 Nov 2024 16:32:48 EST (-0500)
  Is this a bug? (Or am I not seeing something obvious) (Message 1 to 2 of 2)  
From: Anthony D  Baye
Subject: Is this a bug? (Or am I not seeing something obvious)
Date: 23 Apr 2010 13:00:01
Message: <web.4bd1d1b484f85600d7f39bd00@news.povray.org>
I think there's something wrong with the vector computations or the inverse
cosine function.

Given the following code, theta should contain the angle between cV and rV.

Following a series of manipulations to _cD_ and _cP_,
_cD_ = 120 and
_cP_ = <-4, 3, 0>
this means that mag_rV = 5
and the angle between cV and rV should be 180 degrees.

but degrees(acos(vdot(rV,cV))) returns 172

#debug concat("_cD_ = " str(_cD_,6,0) "\n")
#debug concat("_cP_ = <" str(_cP_.x,6,0) ", " str(_cP_.y,6,0) ", "
     str(_cP_.z,6,0)">\n")
#local rV = <0,0,0> - _cP_;
#local mag_rV = sqrt(pow(rV.x,2) + pow(rV.y,2));
#local rV = rV / mag_rV;
#debug concat("rV = <" str(rV.x,6,0) ", " str(rV.y,6,0) ", "
     str(rV.z,6,0)">\n")

#local cV = _cP_ + <cosd(_cD_),sind(_cD_),0>;
#local cV = cV / sqrt(pow(cV.x,2) + pow(cV.y,2));
#debug concat("cV = <" str(cV.x,6,0) ", " str(cV.y,6,0) ", "
     str(cV.z,6,0)">\n")

#local theta = degrees(acos(vdot(rV,cV)));
#debug concat(str(theta,0,0) "\n")
#debug concat(str(mag_rV,0,0) "\n")

confirmation of these results can be obtained by running the following code:

#include "kolors.inc"
#include "math.inc"

light_source { -50.0*z, color rgb 1 }
camera {
     orthographic
     location <0.0, 0.0, -10.0>
     look_at 0.0
     }

#macro init()
#declare _cP_ = <0.0, 0.0, 0.0>;
#declare _cD_ = 0;
#declare _DRAW_ = true;
#end

// Pen Up
#macro pu()
     #declare _DRAW_ = false;
#end

// Pen Down
#macro pd()
     #declare _DRAW_ = true;
#end

// left turn (degrees)
#macro lt(d)
     #declare _cD_ = _cD_ + d;
     #if(_cD_ > 360)
          #declare _cD_ = _cD_ - 360;
     #end
#end

// right turn (degrees)
#macro rt(d)
     #declare _cD_ = _cD_ - d;
     #if(_cD_ < -360)
          #declare _cD_ = _cD_ + 360;
     #end
#end

// foreward (length)
#macro fd(l)
     #local _pL_ = _cP_;
     #declare _cP_ = _cP_ + l*<cosd(_cD_), sind(_cD_), 0>;

     #if(_DRAW_)
          cylinder { _pL_, _cP_, 0.015625 pigment {Orange}
               finish { ambient 0.6 diffuse 0.3 } }
     #end
#end

#macro home()



#debug concat("_cD_ = " str(_cD_,6,0) "\n")
#debug concat("_cP_ = <" str(_cP_.x,6,0) ", " str(_cP_.y,6,0) ", "
     str(_cP_.z,6,0)">\n")
#local rV = <0,0,0> - _cP_;
#local mag_rV = sqrt(pow(rV.x,2) + pow(rV.y,2));
#local rV = rV / mag_rV;
#debug concat("rV = <" str(rV.x,6,0) ", " str(rV.y,6,0) ", "
     str(rV.z,6,0)">\n")

#local cV = _cP_ + <cosd(_cD_),sind(_cD_),0>;
#local cV = cV / sqrt(pow(cV.x,2) + pow(cV.y,2));
#debug concat("cV = <" str(cV.x,6,0) ", " str(cV.y,6,0) ", "
     str(cV.z,6,0)">\n")

#local theta = degrees(acos(vdot(rV,cV)));
#debug concat(str(theta,0,0) "\n")
#debug concat(str(mag_rV,0,0) "\n")

#local hV = <0,0,0>;
/*
lt(theta)
fd(mag_rV)
lt(acos(vdot(rV,hV)))
*/
#end

#macro triline(len)

#if(len < 0.01)
     fd(len)
#else
     triline(len/3)
     lt(60)
     triline(len/3)
     rt(120)
     triline(len/3)
     lt(60)
     triline(len/3)
#end

#end

#macro koch(len)
pu()
lt(90)
fd(len*sind(30) - (len/3)*sind(30))
lt(90)
fd(len/2)
rt(180)
pd()

     #local a = 0;
     #while(a < 3)
          triline(len)
          rt(120)
     #local a = a + 1;
     #end
home()
#end

init()
koch(8)
rt(30)
fd(2)


Post a reply to this message

From: clipka
Subject: Re: Is this a bug? (Or am I not seeing something obvious)
Date: 28 Apr 2010 12:45:36
Message: <4bd86630$1@news.povray.org>
Am 23.04.2010 18:58, schrieb Anthony D. Baye:

> Given the following code, theta should contain the angle between cV and rV.
>
> Following a series of manipulations to _cD_ and _cP_,
> _cD_ = 120 and
> _cP_ =<-4, 3, 0>
> this means that mag_rV = 5
> and the angle between cV and rV should be 180 degrees.

Um... do you have any reasoning /why/ that angle should happen to be 180 
degrees?

Likewise, are you sure that _cP_ /is/ <-4,3,0> in the first place? From 
what I see, you're only printing the integer part of any value to the 
debug output, which is not too helpful when trying to debug 
floating-point math.

(Also note that there exists a special function, vstr(), to convert a 
vector to a string.)


Post a reply to this message

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