|
|
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
|
|