POV-Ray : Newsgroups : povray.tools.general : Norbert Kern's 'Position-Finder' code-- redux Server Time
22 Nov 2026 17:42:35 EST (-0500)
  Norbert Kern's 'Position-Finder' code-- redux (Message 1 to 23 of 23)  
From: Kenneth
Subject: Norbert Kern's 'Position-Finder' code-- redux
Date: 18 Sep 2018 19:05:00
Message: <web.5ba183edb47e1707a47873e10@news.povray.org>
Back in 2006, Norbert posted a really interesting macro 'tool' -- an object
'position finder' (or 'new object placer' as I call it)--that I've only recently
become aware of. (Thanks, Thomas de Groot.) The code had a few flaws that I
thought I would try and fix, as it's quite magical in what it does.  Norbert
even mentioned at the time that in was not very mature. My own code is below, in
a preliminary form. Currently, it's a stand-alone scene, for testing; I want to
turn it into an include file eventually..

The general idea of his code is to add and place an extra object into your scene
after the fact, purely by choosing  pixel coordinates of a 'visual' point in
the screen preview render (or in a rendered image.) His code returns a rotation
and translation that you then plug into your new object, and it magically shows
up in proper 3D space in your re-rendered scene. (Then, you no longer need the
macro.) As Thomas pointed out elsewhere, this sames gobs of time trying to
'deduce'  the new 3D coordinates that you need. (The scene here already includes
a 'new' test object.)

For all of this to work, a 'surface object' in the scene needs to be
pre-#declared and given to the macro-- usually the ground object in your scene;
that surface is traced automatically (within the macro.) It's a key concept of
Norbert's code. But this 'surface' can actually be a union of *many* objects;
then you can choose a position on any of them.

It's still Norbert's magic; I've just tried to make it more consistent. Many of
my own changes were arrived at experimentally, so the code may not be very
elegant. BTW, I didn't want to amateurishly fumble around with his core math;
that's intact.

Something I didn't understand at first: Of the two transforms that are
returned-- rotate and translate-- the rotation actually aligns the placed object
along the surface normal there. That's a nice Norbert touch (but see below.)

Here's Norbert's original code...
http://news.povray.org/povray.binaries.scene-files/attachment/%3Cweb.4478509041a06b1c9bff7e8b0%40news.povray.org%3E/pos
ition_finder.pov.txt


.... and his initial post about it...
http://news.povray.org/povray.binaries.images/thread/%3Cweb.44784f2141a06b1c9bff7e8b0%40news.povray.org%3E/?ttop=423977
&toff=3700


For picking  the 'point of interest' in the initial preview render (the 2-D x/y
pixel position), Norbert originally chose to use screen *percentages*. I thought
of changing that to the render's actual pixel positions-- but Norbert's idea is
better: the code doesn't depend on the actual size/resolution/aspect ratio of a
render; that's taken care of automatically. (The slight CHANGE I made to that
scheme is, instead of the render percentage going from 0 to 100, it's now 0 to
1000 to get better precision for the point-of-interest-- simply because of the
way POV-ray shows percentages at the upper-left corner of a render preview when
you move your mouse cursor around: like 0.216 for the x-percentage there, which
would then be 216 as used in the code.)

A BIG caveat: I don't like posting code when I know it still has flaws, but
that's the case here, But rather than continuing to work on it for the next
week/month/year(!), I wanted to get it out for testing.  The remaining flaw is
*specific* to chosen points on the 'underside' of objects (like the lower half
of a sphere.) As far as I can tell, the original code was not designed for this
situation. The trouble appears to be when Norm.y goes *negative*, and might also
depend on the camera location vs. the 'point-of-interest' (the vector between
the two.) I think  the code lines that use   vaxis_rotate   and/or   atan2  are
the culprits,   but I don't know how to fix them, try as I might. Some things
need 'flipping' somewhere, when Norm.y goes negative. I tried lots of different
ad-hoc code additions elsewhere-- kludges, really-- which do work in *most*
circumstances but not all. (For example, my experiments worked for the underside
of horizontal cylinders , but not spheres.) For clarity's sake (and sanity!), I
left out all of that stuff.  But if you restrict the point-of-interest to the
'upper surface' of objects, it seems to work consistently.

Also: The found rotation (based on the traced normal of the 'surface') is not
very accurate at times; put another way, the rotation gets better as the traced
normal approaches the  +y direction (and not just 90-degrees orthogonal to any
particular surface, but basically parallel to the sky vector.) I've tried lots
of workarounds for this, but I haven't been able to disentangle all the things
that are going on.  (To see this effect, try some positions on the upper
hemisphere of the large sphere but close to the horizontal mid-line; also move
the camera around.)

HOWEVER, the found *position* always works the way it should. AFAIK!

Some of my changes:
* The macro has its own camera now (temporary, used only when the macro is
actually in use.) It replaces your scene's camera, but uses the same data which
you supply.

* The camera and its look-at point can be anywhere now , with consistent results
(although I haven't tested EVERY possible combination)

* The indicator arrow now remains the same size (more or less), no matter where
it  happens to be in 3D space. IMO, this aids clarity.

* The on-screen text is now fixed in the upper-left of the render. (I used a
matrix to do that, but I can't take credit for it-- it's 'borrowed' from the
original screen.inc file.)

* A strange mirror-flipping behavior (along the x-axis) has been eliminated.

* Note that it only works with a typical perspective camera.

*The code seems to be more precise if, for cam_ang, you use more of a 'zoom'
angle than a wide-angle (i.e., 30 is better than 67, for example.) This would
just be temporary, until the new object is correctly placed and you no longer
need the macro.

---------------- the code ------------
// 9/1-16/18   [Norbet Kern's original code from 2006, with modifications
// by Kenneth Walker]

#version 3.7;  // or 3.71 or 3.8
global_settings{assumed_gamma 1.0}

// definitions (for test scene below) _____________________________________
#declare screen_x_position = 420; // screen percentages X 1000  (0 to 1000)
#declare screen_y_position = 623; // ditto

#declare cam_loc = <2,4,-8>;
#declare lookat  = <.3,-.1,-.2>;
#declare cam_ang = 50; // 36

// [optional origin markers; pointing only in the POSITIVE directions]
union{
cylinder{0,.8*x .03 pigment{rgb 1.5}}     // X-- WHITE
cylinder{0,.8*y .03 pigment{rgb <0,1,0>}} // Y-- GREEN
cylinder{0,.8*z .03 pigment{rgb <0,.2,1>}} // Z-- BLUE
text{ttf "cyrvetic.ttf" "+ X" 0.2, 0 scale .28
     translate <.9,.04,0> pigment{rgb 1.5} no_shadow} // " + X"
text{ttf "cyrvetic.ttf" "+ Y" 0.2, 0 scale .28
     translate <-.2,.9,0> pigment{rgb <0,1,0>} no_shadow} // " + Y"
text{ttf "cyrvetic.ttf" "+ Z" 0.2, 0 scale .28
     translate <-.13,.04,.9> pigment{rgb <0,.2,1>} no_shadow} // "+ Z"
      scale 1.3
      translate .19*y
    }

// [The NEW object you want to place in the scene...]
#declare NEW_OBJECT =
union{
cylinder{0,.6*x .06 pigment {rgb 1.5}} //     WHITE for x-axis
cylinder{0,.6*y .06 pigment {rgb <0,1,0>}} // GREEN for y-axis
cylinder{0,.6*z .06 pigment{rgb <0,.2,1>}} //  BLUE for z-axis
box{0,.3 translate -.15 pigment{rgb <1,.7,0>}} // YELLOW
    scale .7
    translate .15*y
}

#declare SURFACE =
union{
height_field {
    function 500,500 {
            pattern {bozo scale 0.08}
    }
 smooth
 translate <-0.5,0,-0.5>
 scale <7,0.4,7>
 texture {
         pigment{
              average
              pigment_map{
                      [1.0 rgb <0.5,1,0.3>]
                      [0.6 gradient x frequency 8
                           color_map{
                                    [.07 rgb -.3]
                                    [.07 rgb <0.7,1,0.7>]
                                    }
                      ]
                      [0.6 gradient z frequency 8
                           color_map{
                                    [.07 rgb -.3]
                                    [.07 rgb <0.7,1,0.7>]
                                    }
                      ]
                        }
                  }
         finish {ambient 0 diffuse 0.5}
         }
             }
sphere{0,.9
pigment{
        average
        pigment_map{
             [1.0 planar
                  pigment_map{
                    [.5 bumps scale 2]
                    [.5 rgb -.5]
                            }
             ]
             [1.0 planar
                  pigment_map{
                    [.5 bumps scale 2]
                    [.5 rgb -.5]
                            }
                  rotate 90*z
             ]
             [1.0 planar
                  pigment_map{
                    [.5 bumps scale 2]
                    [.5 rgb -.5]
                            }
                  rotate 90*x
             ]
                  }
        scale .03
       }
   translate <-1.8,.85,1.8>
    }
box{0,2 translate -1 rotate 45*x rotate 45*z
pigment{bumps scale .05}
translate <-1.8,-.6,-1.5>
}
union{
cylinder {-1.4*z,1.4*z, .7
pigment{
        average
        pigment_map{
             [1.0 planar
                  pigment_map{
                    [.5 bumps scale 2]
                    [.5 rgb -.1]
                            }
             ]
             [1.0 planar
                  pigment_map{
                    [.5 bumps scale 2]
                    [.5 rgb -.1]
                            }
                  rotate 90*z
             ]
                  }
        scale .03
       }
       translate <1.5,0,0>
    }
cylinder {-1.4*z,1.4*z, .7
pigment{
        average
        pigment_map{
             [1.0 planar
                  pigment_map{
                    [.5 bumps scale 2]
                    [.5 rgb -.1]
                            }
             ]
             [1.0 planar
                  pigment_map{
                    [.5 bumps scale 2]
                    [.5 rgb -.1]
                            }
                  rotate 90*z
             ]
                  }
        scale .03
       }
       rotate -90*y
       translate <2.8,0,1.4>
    }
    rotate 90*y
    translate <1.5,.7,4.0>
    }
} // end of 'SURFACE' union


// creating the macro___________________________________________________
#macro pos_finder (SURFACE, cam_loc, lookat, cam_ang, screen_x_position,
screen_y_position, arrow_scale)
#if(cam_loc.z <= 0)
// do nothing
#else
#local screen_x_position = 1000 - screen_x_position;
#end

#local screen_x_position = screen_x_position/10;
#local screen_y_position = screen_y_position/10;

#local cam_mirror = #if(cam_loc.z < lookat.z) -1; #else 1; #end
#local cam_z = 0.5*image_width/image_height/tan(radians(cam_ang*0.5));
#local cam_a = cam_mirror*image_width/image_height;
#local cam_s = y;
#local cam_d = vnormalize (lookat-cam_loc);
#local cam_r = vnormalize (vcross(cam_s,cam_d));
#local cam_up = vnormalize (vcross(cam_d,cam_r));
#local cam_dir = cam_d*cam_z;
#local cam_right = cam_r*cam_a;

#local TEXT_OBJECT_TRANSFORM =
   transform {
      matrix <
         cam_r.x, cam_r.y, cam_r.z,
         cam_up.x, cam_up.y, cam_up.z,
         cam_d.x, cam_d.y, cam_d.z,
         cam_loc.x, cam_loc.y, cam_loc.z
             >
             }

#local dir_y = vaxis_rotate (lookat-cam_loc,vcross (lookat-cam_loc,cam_up),
(0.5-screen_y_position*0.01)*cam_ang/image_width*image_height);
#local dir_xy = vaxis_rotate (dir_y,cam_up,
(0.5-screen_x_position*0.01)*cam_mirror*cam_ang);

#local Norm = <0,0,0>;
#local Inter = trace (SURFACE,cam_loc,dir_xy,Norm);
#if (vlength (Norm) != 0)
        #local rx = degrees (atan2 (Norm.z,Norm.y + .0001));
        #local rz = -degrees (atan2 (Norm.x,Norm.y + .0001));
        #local precise = 3;

       union{
          cylinder {0.2*y,0.6*y,0.02}
          cone {0,0,0.2*y,0.06}
          text{ttf "cyrvetic.ttf" "POV-Ray" 0.2,
          0 scale .2 translate <-.40,.5,-.02>} // "POV-Ray"
                rotate <rx,0,rz>
                scale arrow_scale*.0040*vlength(cam_loc - Inter)*cam_ang
                texture{
                pigment {color rgb .6*x}
                finish {ambient .15 diffuse .85 specular 0.3 roughness 0.1}
                       }
                translate Inter
                 }
       union{
          text{
              ttf "cyrvetic.ttf"
              concat ("rotate <",str (rx,0,precise-1),",0,",
              str (rz,0,precise-1),">")
              0.02,0
              translate .6*y
              }
       text{
           ttf "cyrvetic.ttf"
           concat ("translate <",str (Inter.x,0,precise),",",
           str (Inter.y,0,precise),",",str (Inter.z,0,precise),">")
           0.02,0
           translate -.6*y
            }
    no_shadow
    scale .025*(cam_ang)/90
    translate <-.38*(cam_ang/90),.32*(image_height/image_width)*
   (cam_ang/90),.5>
    transform{TEXT_OBJECT_TRANSFORM}
    pigment {color rgb z}
    finish {ambient .15 diffuse .85}
         }

#debug concat ("\n","rotate  <",str (rx,0,precise-1),",0,",
str (rz,0,precise-1),">\n")
#debug concat ("\n","translate <",str (Inter.x,0,precise),",",
str (Inter.y,0,precise),",",str (Inter.z,0,precise),">\n\n")
#else
#debug concat ("\n","chosen position not on traced SURFACE, please try
        other screen_x_position or screen_y_position values\n\n")
#end

camera {
        perspective
        location cam_loc
        look_at lookat
        right cam_right
        angle cam_ang
        direction -z
}
#end  // [end of macro]

// test scene __________________________________________________________________

// The macro call
pos_finder (SURFACE, cam_loc, lookat, cam_ang, screen_x_position,
screen_y_position, 1.0)

light_source {0 color rgb .7 translate <-200,200,-200>}
light_source {0 color rgb .7 translate <200,200,200>}

background {color rgb .7}

object {SURFACE}

object{NEW_OBJECT

// rotate ...*y // [optional, in case you don't like the basic x or
// z 'direction' that the new object is pointing in. This needs to come
// BEFORE the following transforms that are returned from the code]

// [the RETURNED on-screen rotation and translation-- replace with the
// new ones, in this order]
rotate    <5.01,0,5.12>

translate <2.844,0.229,-2.911>
}


Post a reply to this message

From: Bald Eagle
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 18 Sep 2018 21:55:00
Message: <web.5ba1aba5bb085d6c458c7afe0@news.povray.org>
Nice job, Walker.   :)

Thanks to you, I understand much better what this whole thing is all about.

I'll see if maybe I have some time to sketch it out and run some experiments to
see where the bugs are coming from.   But as we know, I have my good days, and I
have my bad days   ;)

Perhaps the 'surface' ought to be renamed the 'target group' or 'target
object[s]' since it clarifies the use of trace.

I tried the macro with a point not on the 'surface' and just got the macro
message - I'm wondering if instead the macro ought to return a normalized vector
indicating the direction from the camera to that selected pixel.

Then you could translate the object to the camera position, and then some
multiple along that vector, so that you could place things "in the air".

I suppose a vertical semi-transparent plane would work just as well.

I wonder just how much photogrammetry could be developed along these lines...
https://www.popsci.com/technology/article/2011-10/new-program-slips-super-accurate-false-images-existing-photographs


Keep up the good work   :)


Post a reply to this message

From: Kenneth
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 19 Sep 2018 01:40:01
Message: <web.5ba1e030bb085d6ca47873e10@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> Nice job, Walker.   :)

Thanks! I've been *slaving* over this code, day after day. (But I'm still
irritated that I couldn't get it completely worked out. I haven't given up yet!)
You may have already guessed that my recent post about matrix use and transforms
was a last-ditch effort to solve the remaining flaws in this code.

>
> I tried the macro with a point not on the 'surface' and just got the macro
> message - I'm wondering if instead the macro ought to return a normalized vector
> indicating the direction from the camera to that selected pixel.
>
> Then you could translate the object to the camera position, and then some
> multiple along that vector, so that you could place things "in the air".

Like you, I've been wondering how to get such 'in air' positions, which didn't
seem possible with the way the code was constructed. But I tried some more
tests, per your suggestion (going about it the wrong way, naturally), and
realized that your PLANE idea wouldn't need such an arrow...
>
> I suppose a vertical semi-transparent plane would work just as well.
>

That is a brilliant idea! It didn't occur to me at all. And the plane can be
positioned (and rotated if necessary) to get any in-air position anywhere. Add
this code into the SURFACE object-union (and comment it out if it's not
needed)...

plane{z,0  // a transparent plane, for picking positions IN SPACE
     texture {
  pigment{
     average
     pigment_map{
     [0.6 gradient x frequency 8
          color_map{
                  [.07 rgb -.3]
                  [.07 rgbt <1,0,0,.7>]
                  }
     ]
     [0.6 gradient y frequency 8
         color_map{
                  [.07 rgb -.3]
                  [.07 rgbt <1,0,0,.7>]
                  }
     ]
                }
       }
  finish {ambient 0 emission .5 diffuse 0}
     }
  rotate 37   // whatever you want
  translate -1.3*z // wherever you want to put it
    }

BTW: When an in-air POSITION is returned, it's probably best to ignore the found
ROTATION-- as it has no real meaning re: the normal traced on that 'artificial
plane'.


Post a reply to this message

From: Thomas de Groot
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 19 Sep 2018 03:05:02
Message: <5ba1f51e$1@news.povray.org>
On 19-9-2018 1:02, Kenneth wrote:
> Back in 2006, Norbert posted a really interesting macro 'tool' -- an object
> 'position finder' (or 'new object placer' as I call it)--that I've only recently
> become aware of. (Thanks, Thomas de Groot.) The code had a few flaws that I
> thought I would try and fix, as it's quite magical in what it does.  Norbert
> even mentioned at the time that in was not very mature. My own code is below, in
> a preliminary form. Currently, it's a stand-alone scene, for testing; I want to
> turn it into an include file eventually..
> 

Well done, sir! I have little time at this particular moment, but be 
sure that I am going to test your code. Just wanted you to know that I 
was aware.

-- 
Thomas


Post a reply to this message

From: Kenneth
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 19 Sep 2018 05:40:00
Message: <web.5ba21902bb085d6ca47873e10@news.povray.org>
Thomas de Groot <tho### [at] degrootorg> wrote:

>
> Well done, sir! I have little time at this particular moment, but be
> sure that I am going to test your code. Just wanted you to know that I
> was aware.
>

Many thanks!

NOW, I'm finally going to take a leisurely look at your own code. I was on a
"mission from God" (as the Blues Brothers would say), to see how far I could get
on my own. Wow, did that hurt my brain!! Fun yet frustrating, at the same time.


Post a reply to this message

From: Kenneth
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 19 Sep 2018 16:30:00
Message: <web.5ba2b12fbb085d6ca47873e10@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

>
> *The code seems to be more precise if, for cam_ang, you use more of a 'zoom'
> angle than a wide-angle (i.e., 30 is better than 67, for example.) This would
> just be temporary, until the new object is correctly placed and you no longer
> need the macro.
>

Hmm. The 2nd part of that little paragraph needs clarifying (only because the
code is presently a self-contained test scene): The accurate placement of an
object *depends* on the camera angle (cam_ang) staying the same. It needs to be
pre-set with whatever value you choose, and NOT changed (at least *while* using
the macro). For example, with a given set of...

cam_loc
lookat
cam_ang

....for the camera, the preview render will look the way you want, and you then
choose a 'point of interest' in the scene. If you then *change* cam_angle, that
chosen point will not be where you thought it would be-- since the essence of
the code is to work solely with the visual on-screen preview (which 'sets' the
point of interest BASED ON the three parameters.) A different cam_angle would
naturally create a different-looking on-screen preview.

Again, this caveat applies only to the current test scene set-up.

BTW, you CAN currently use the macro itself in one of your own scenes, to try it
out. Just make sure the three camera parameters match those of the 'real' camera
in your scene. (And the macro call needs to go somewhere AFTER your own scene
camera; the macro's built-in camera temporarily replaces it.) Once you've placed
your new object, you no longer need the macro, and you can then change your own
camera parameters to whatever you like.


Post a reply to this message

From: Thomas de Groot
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 23 Sep 2018 07:27:29
Message: <5ba778a1@news.povray.org>
On 19-9-2018 11:38, Kenneth wrote:
> Thomas de Groot <tho### [at] degrootorg> wrote:
> 
>>
>> Well done, sir! I have little time at this particular moment, but be
>> sure that I am going to test your code. Just wanted you to know that I
>> was aware.
>>
> 
> Many thanks!
> 
> NOW, I'm finally going to take a leisurely look at your own code. I was on a
> "mission from God" (as the Blues Brothers would say), to see how far I could get
> on my own. Wow, did that hurt my brain!! Fun yet frustrating, at the same time.
> 
> 
> 

I like it! I really do, and I shall replace my own version with yours.

-- 
Thomas


Post a reply to this message

From: Kenneth
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 23 Sep 2018 15:30:00
Message: <web.5ba7e902bb085d6ca47873e10@news.povray.org>
Thomas de Groot <tho### [at] degrootorg> wrote:
>
> I like it! I really do, and I shall replace my own version with yours.
>

Thanks, glad to hear that it's useful!

I may re-instate my 'kludge' fixes for some of the remaining traced 'normal'
behavior; I found a way to include that stuff in a brute-force kind of way (it's
not very elegant code, but produces results.) I'm currently running more tests,
to see if there are *other* kludges that I need to add ;-)  If it all works out
in a satisfactory way, I'll post the updated macro here.


Post a reply to this message

From: Thomas de Groot
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 24 Sep 2018 03:22:24
Message: <5ba890b0$1@news.povray.org>
On 23-9-2018 21:26, Kenneth wrote:
> Thomas de Groot <tho### [at] degrootorg> wrote:
>>
>> I like it! I really do, and I shall replace my own version with yours.
>>
> 
> Thanks, glad to hear that it's useful!
> 
> I may re-instate my 'kludge' fixes for some of the remaining traced 'normal'
> behavior; I found a way to include that stuff in a brute-force kind of way (it's
> not very elegant code, but produces results.) I'm currently running more tests,
> to see if there are *other* kludges that I need to add ;-)  If it all works out
> in a satisfactory way, I'll post the updated macro here.
> 
> 

That would be excellent.

-- 
Thomas


Post a reply to this message

From: Kenneth
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 25 Sep 2018 16:15:01
Message: <web.5baa96aebb085d6ca47873e10@news.povray.org>
Thomas de Groot <tho### [at] degrootorg> wrote:

> > I like it! I really do, and I shall replace my own version with yours.

> >
> > I may re-instate my 'kludge' fixes for some of the remaining traced 'normal'
> > behavior...

I've just come across another subtle flaw in the code-- NOT normal-related--
that's probably been there since my *early* experiments. I  may have introduced
it with my own fixes, I don't know. Basically, *sometimes* the arrow or 'new'
object suddenly flips from one side of the preview render to the other. But it
happens only with certain juxtapositions of camera and lookat point, and their
positions relative to the x/y plane at the origin. It's strange that I didn't
see this flaw previously,  even after 100-plus tests of the code! (All my
previsous tests just happened to avoid this situation, amazingly.)

Luckily, I've been able to deduce the 'rules' that govern this behavior, so I'll
add a fix for it-- as soon as I figure out how ;-)


Post a reply to this message

From: Thomas de Groot
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 26 Sep 2018 02:33:04
Message: <5bab2820$1@news.povray.org>
On 25-9-2018 22:12, Kenneth wrote:
> Thomas de Groot <tho### [at] degrootorg> wrote:
> 
>>> I like it! I really do, and I shall replace my own version with yours.
> 
>>>
>>> I may re-instate my 'kludge' fixes for some of the remaining traced 'normal'
>>> behavior...
> 
> I've just come across another subtle flaw in the code-- NOT normal-related--
> that's probably been there since my *early* experiments. I  may have introduced
> it with my own fixes, I don't know. Basically, *sometimes* the arrow or 'new'
> object suddenly flips from one side of the preview render to the other. But it
> happens only with certain juxtapositions of camera and lookat point, and their
> positions relative to the x/y plane at the origin. It's strange that I didn't
> see this flaw previously,  even after 100-plus tests of the code! (All my
> previsous tests just happened to avoid this situation, amazingly.)
> 
> Luckily, I've been able to deduce the 'rules' that govern this behavior, so I'll
> add a fix for it-- as soon as I figure out how ;-)
> 

That is strange and I have no clue - nor experience - about this.

Something else though, troubles me from even before your work. There are 
scenes where the results from the trace are significantly away from the 
initial screen position given to the macro. I shall try to get a demo 
scene together where this is demonstrated.

-- 
Thomas


Post a reply to this message

From: Thomas de Groot
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 26 Sep 2018 03:39:53
Message: <5bab37c9$1@news.povray.org>
On 26-9-2018 8:32, Thomas de Groot wrote:
> Something else though, troubles me from even before your work. There are 
> scenes where the results from the trace are significantly away from the 
> initial screen position given to the macro. I shall try to get a demo 
> scene together where this is demonstrated.
> 

I have got a test scene where the problem is demonstrated. I attach it 
here, together with a slightly changed version of your position finder 
and Gilles Tran's Visibility Test macro (which might be necessary). This 
last one I often use to get the right zoom value for the camera in order 
to calculate traces exactly within the visible screen scene. If I make 
myself understood... I don't think however, from my testing, that that 
influences the issue at hand in any way.

I am curious to learn what you think.

-- 
Thomas


Post a reply to this message


Attachments:
Download 'islaytest.7z.zip' (6 KB)

From: Kenneth
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 26 Sep 2018 14:35:03
Message: <web.5babd105bb085d6ca47873e10@news.povray.org>
Thomas de Groot <tho### [at] degrootorg> wrote:
>
> I have got a test scene where the problem is demonstrated. I attach it
> here, together with a slightly changed version of your position finder
> and Gilles Tran's Visibility Test macro...

Thanks! I will investigate this. Gille's macro is also new to me-- so
double-thanks for bringing it to my attention :-)

My many code trials have been real brain-twisters; sometimes one 'fix'
introduces yet another problem. At times, I've had to step away from the code to
regain my sanity ;-) But it's *slowly* improving as I continue work on it.


Post a reply to this message

From: Kenneth
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 26 Sep 2018 18:10:00
Message: <web.5bac01adbb085d6ca47873e10@news.povray.org>
Thomas de Groot <tho### [at] degrootorg> wrote:
> On 26-9-2018 8:32, Thomas de Groot wrote:
> > Something else though, troubles me from even before your work. There are
> > scenes where the results from the trace are significantly away from the
> > initial screen position given to the macro...
> >
>
> I have got a test scene where the problem is demonstrated...

Yes, I've noticed as well that the found translation doesn't always agree with
the 'point-of-interest' that's chosen. I think the problem is based on the given
camera angle. In my earlier tests, I tried to include a slight 'fudge factor'
value to correct for this-- but found that the value needed to change
dynamically (in a way that I couldn't figure out.) It *may* be because screen
size vs. camera angle is not a 'linear' relationship(?), although I haven't
really investigated that, nor as to how Norbert's code is actually using cam_ang
in his math. As a practical solution, my *own* fix for this position problem is
to simply change the found translation vector values until things look correct!
:-P

BTW, I noticed a slight mistake in your code:
[Given]
//=======================================
// TEST ROD
// ======================================
//Rod at position given by:
//#declare screen_x_position = 260;
//#declare screen_y_position = 850;
cylinder {<0,0,0>, <0,100,0>,5 pigment {rgb <1,1,0>}
translate <-2426.313, -269.700, -1300.118>
}

..... but the actual translation that's returned from those screen percentages is
translate <-2315.395, -298.978, -1668.753>

There's still a position error, but not quite as large.

As an experiment to see the effect of a changing camera angle, try this (but
first make your rod object a little taller--
cylinder {<0,0,0>, <0,500,0>,5

Then,
CamAng (or cam_ang) = 15;

ROD translation:
translate <-2180.222, -99.162, -876.054>

Now, try to choose the screen coordinates of the rod on your Landscape
(screen_x_position and screen_y_position.) My own visual attempt is at the
screen precentages 126,873-- which places the arrow almost exactly where it's
supposed to go  :-)

But now, change CamAng to 80 (leaving the rod where it is), and repeat the
trial. (Hopefully, you can still see the rod!) My best guess for the new screen
percentages is 442,558-- and there's now a slight offest in the arrow position.

As a practical solution to the offset problem, it's probably best to use more of
a 'zoom' camera angle to initially choose a point-of-interest and to place the
object.

(BTW: Gille's macro doesn't appear to interfere in any way with the
position-finder macro or vice-versa, so no worries there. Neither macro depends
on the other, as they are different as to their purposes, so both can be used at
the same time-- as you have been doing, of course.)


Post a reply to this message

From: Kenneth
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 27 Sep 2018 00:10:01
Message: <web.5bac571cbb085d6ca47873e10@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
> >
> > I have got a test scene where the problem is demonstrated...
>
> Yes, I've noticed as well that the found translation doesn't always agree with
> the 'point-of-interest' that's chosen. I think the problem is based on
> the given camera angle.... It *may* be because screen
> size vs. camera angle is not a 'linear' relationship(?)...

Sorry if that sounded confusing; 'screen size' was the wrong phrase. What I
meant was, there may be a non-linear relationship between camera angle and the
resulting view in a render or screen preview-- meaning, as the angle value goes
higher (more wide-angle), the camera view takes in a larger portion of the
scene, but the change may not follow a strictly linear relationship to the
changing angle. (The change in the 'visual' distance between two objects, vs.
the
real POV-ray distance there.) I've never tested this; it would be interesting
to construct a plot of distance values (as seen in the preview render,
horizontally for example) with the camera angle changing all the way from 1 to
90(!)


Post a reply to this message

From: Thomas de Groot
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 27 Sep 2018 02:43:37
Message: <5bac7c19$1@news.povray.org>
On 27-9-2018 6:09, Kenneth wrote:
> "Kenneth" <kdw### [at] gmailcom> wrote:
>>>
>>> I have got a test scene where the problem is demonstrated...
>>
>> Yes, I've noticed as well that the found translation doesn't always agree with
>> the 'point-of-interest' that's chosen. I think the problem is based on
>> the given camera angle.... It *may* be because screen
>> size vs. camera angle is not a 'linear' relationship(?)...
> 
> Sorry if that sounded confusing; 'screen size' was the wrong phrase. What I
> meant was, there may be a non-linear relationship between camera angle and the
> resulting view in a render or screen preview-- meaning, as the angle value goes
> higher (more wide-angle), the camera view takes in a larger portion of the
> scene, but the change may not follow a strictly linear relationship to the
> changing angle. (The change in the 'visual' distance between two objects, vs.
> the
> real POV-ray distance there.) I've never tested this; it would be interesting
> to construct a plot of distance values (as seen in the preview render,
> horizontally for example) with the camera angle changing all the way from 1 to
> 90(!)
> 

You have brought a couple of interesting things to my attention. I have 
scratched my head a lot in the past without results, so now I am going 
to test this again: My next week-end seems booked ;-)

-- 
Thomas


Post a reply to this message

From: Thomas de Groot
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 27 Sep 2018 03:14:23
Message: <5bac834f$1@news.povray.org>
On 27-9-2018 0:09, Kenneth wrote:
> Thomas de Groot <tho### [at] degrootorg> wrote:
>> On 26-9-2018 8:32, Thomas de Groot wrote:
>>> Something else though, troubles me from even before your work. There are
>>> scenes where the results from the trace are significantly away from the
>>> initial screen position given to the macro...
>>>
>>
>> I have got a test scene where the problem is demonstrated...
> 
> Yes, I've noticed as well that the found translation doesn't always agree with
> the 'point-of-interest' that's chosen. I think the problem is based on the given
> camera angle. In my earlier tests, I tried to include a slight 'fudge factor'
> value to correct for this-- but found that the value needed to change
> dynamically (in a way that I couldn't figure out.) It *may* be because screen
> size vs. camera angle is not a 'linear' relationship(?), although I haven't
> really investigated that, nor as to how Norbert's code is actually using cam_ang
> in his math. As a practical solution, my *own* fix for this position problem is
> to simply change the found translation vector values until things look correct!
> :-P
> 

Yep! That was my practical solution too! :-) Still, I do not quite 
understand /why/ this happens though. My naive reasoning would tell me 
it should not, but then of course, what do I know about the deeper 
arcane workings of ray-tracing?

> BTW, I noticed a slight mistake in your code:
> [Given]
> //=======================================
> // TEST ROD
> // ======================================
> //Rod at position given by:
> //#declare screen_x_position = 260;
> //#declare screen_y_position = 850;
> cylinder {<0,0,0>, <0,100,0>,5 pigment {rgb <1,1,0>}
> translate <-2426.313, -269.700, -1300.118>
> }
> 
> ..... but the actual translation that's returned from those screen percentages is
> translate <-2315.395, -298.978, -1668.753>
> 
> There's still a position error, but not quite as large.

That is bizarre because I literally copied the translation values from 
the screen. So there seems to be a slight difference between computers 
too...

> 
> As an experiment to see the effect of a changing camera angle, try this (but
> first make your rod object a little taller--
> cylinder {<0,0,0>, <0,500,0>,5
> 
> Then,
> CamAng (or cam_ang) = 15;
> 
> ROD translation:
> translate <-2180.222, -99.162, -876.054>
> 
> Now, try to choose the screen coordinates of the rod on your Landscape
> (screen_x_position and screen_y_position.) My own visual attempt is at the
> screen precentages 126,873-- which places the arrow almost exactly where it's
> supposed to go  :-)
> 
> But now, change CamAng to 80 (leaving the rod where it is), and repeat the
> trial. (Hopefully, you can still see the rod!) My best guess for the new screen
> percentages is 442,558-- and there's now a slight offest in the arrow position.
> 
> As a practical solution to the offset problem, it's probably best to use more of
> a 'zoom' camera angle to initially choose a point-of-interest and to place the
> object.

I am going to do this homework thoroughly...

> 
> (BTW: Gille's macro doesn't appear to interfere in any way with the
> position-finder macro or vice-versa, so no worries there. Neither macro depends
> on the other, as they are different as to their purposes, so both can be used at
> the same time-- as you have been doing, of course.)
> 

I thought you would be interested. It is very helpful to me as I 
regularly automatically trace large number of objects (like trees) on my 
landscapes. It helps to sift out all those positions falling outside of 
the screen.

-- 
Thomas


Post a reply to this message

From: Kenneth
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 27 Sep 2018 14:30:07
Message: <web.5bad2103bb085d6ca47873e10@news.povray.org>
Thomas de Groot <tho### [at] degrootorg> wrote:
> On 27-9-2018 0:09, Kenneth wrote:
> > Thomas de Groot <tho### [at] degrootorg> wrote:

>
> > BTW, I noticed a slight mistake in your code:
> > [Given]
> > //=======================================
> > // TEST ROD
> > // ======================================
> > //Rod at position given by:
> > //#declare screen_x_position = 260;
> > //#declare screen_y_position = 850;
> > cylinder {<0,0,0>, <0,100,0>,5 pigment {rgb <1,1,0>}
> > translate <-2426.313, -269.700, -1300.118>
> > }
> >
> > ..... but the actual translation that's returned from those screen
> > percentages is
> > translate <-2315.395, -298.978, -1668.753>
> >
> > There's still a position error, but not quite as large.
>
> That is bizarre because I literally copied the translation values from
> the screen. So there seems to be a slight difference between computers
> too...
>

Well, I discovered why we arrived at different values: It was a really simple
and dumb mistake I made. I've been running your code tests at 800X600
resolution; I didn't notice that your own tests used 1280X640. Uh, that does
make a difference :-)  Using your aspect ratio, my values now agree with yours.
Duh. Sorry for the confusion-- and I'm glad it turned out to be so simple!!
> >
> > As an experiment to see the effect of a changing camera angle, try this...

Well, those values are now wrong as well :-O  Although, it would still be useful
for you to run two renders with vastly different camera angle values, to see how
the found translation value gets more accurate at 'telephoto/zoom' settings.

BTW, Norbert's position-finder code also #debugs the found rotation/translation
values to the message pane. My own (Windows) set-up for *using* those values is
to go there, then EDIT/COPY PANE, then paste the contents into Windows' Wordpad
or Notepad. Then, I re-copy the two values and simply paste them into my scene
code. (Instead of copying them by eye from the preview render.) It's fast and
foolproof.

Meanwhile, I continue working...


Post a reply to this message

From: Bald Eagle
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 27 Sep 2018 15:05:00
Message: <web.5bad293ebb085d6cc437ac910@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

> BTW, Norbert's position-finder code also #debugs the found rotation/translation
> values to the message pane. My own (Windows) set-up for *using* those values is
> to go there, then EDIT/COPY PANE, then paste the contents into Windows' Wordpad
> or Notepad. Then, I re-copy the two values and simply paste them into my scene
> code. (Instead of copying them by eye from the preview render.) It's fast and
> foolproof.


I had the idea that it would be a handy feature to be able to write directly to
the clipboard from POV-Ray.
Not sure how much that would take under-the-hood to do...


Post a reply to this message

From: Stephen
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 27 Sep 2018 15:30:00
Message: <5bad2fb8$1@news.povray.org>
On 27/09/2018 19:29, Kenneth wrote:
>   My own (Windows) set-up for*using*  those values is
> to go there, then EDIT/COPY PANE, then paste the contents into Windows' Wordpad
> or Notepad. Then, I re-copy the two values and simply paste them into my scene
> code. (Instead of copying them by eye from the preview render.) It's fast and
> foolproof.


There is a nice little TRS utility called Capture2Text that selects a 
portion of your screen then OCR's the text and copies it to the 
clipboard. I find it very handy.

http://capture2text.sourceforge.net/

-- 

Regards
     Stephen


Post a reply to this message

From: Thomas de Groot
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 28 Sep 2018 02:27:26
Message: <5badc9ce$1@news.povray.org>
On 27-9-2018 21:29, Stephen wrote:
> On 27/09/2018 19:29, Kenneth wrote:
>>   My own (Windows) set-up for*using*  those values is
>> to go there, then EDIT/COPY PANE, then paste the contents into 
>> Windows' Wordpad
>> or Notepad. Then, I re-copy the two values and simply paste them into 
>> my scene
>> code. (Instead of copying them by eye from the preview render.) It's 
>> fast and
>> foolproof.
> 
> 
> There is a nice little TRS utility called Capture2Text that selects a 
> portion of your screen then OCR's the text and copies it to the 
> clipboard. I find it very handy.
> 
> http://capture2text.sourceforge.net/
> 

Thanks! That is very useful!

-- 
Thomas


Post a reply to this message

From: Thomas de Groot
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 28 Sep 2018 03:30:47
Message: <5badd8a7@news.povray.org>
On 27-9-2018 20:29, Kenneth wrote:
> Thomas de Groot <tho### [at] degrootorg> wrote:
>> On 27-9-2018 0:09, Kenneth wrote:
>>> Thomas de Groot <tho### [at] degrootorg> wrote:
> 
>>
>>> BTW, I noticed a slight mistake in your code:
>>> [Given]
>>> //=======================================
>>> // TEST ROD
>>> // ======================================
>>> //Rod at position given by:
>>> //#declare screen_x_position = 260;
>>> //#declare screen_y_position = 850;
>>> cylinder {<0,0,0>, <0,100,0>,5 pigment {rgb <1,1,0>}
>>> translate <-2426.313, -269.700, -1300.118>
>>> }
>>>
>>> ..... but the actual translation that's returned from those screen
>>> percentages is
>>> translate <-2315.395, -298.978, -1668.753>
>>>
>>> There's still a position error, but not quite as large.
>>
>> That is bizarre because I literally copied the translation values from
>> the screen. So there seems to be a slight difference between computers
>> too...
>>
> 
> Well, I discovered why we arrived at different values: It was a really simple
> and dumb mistake I made. I've been running your code tests at 800X600
> resolution; I didn't notice that your own tests used 1280X640. Uh, that does
> make a difference :-)  Using your aspect ratio, my values now agree with yours.
> Duh. Sorry for the confusion-- and I'm glad it turned out to be so simple!!

Ouch! glad it is solved! I should have mentioned the change in aspect 
ratio. One of the things I tested was if widely different aspect ratio's 
influenced the outcome, but no.

Something I thought about this night: would the height_field resolution 
influence the trace? compared to a primitive object? Answer: no, it does 
not.

Next, after I restored the lineation on the height_field, I found 
something for your thoughts. It appears, at least in my test file, that 
the shift is /only/ along the z-axis, and furthermore, that the shift 
approximates 200 pov units. Is that chance? Is it significant? I have no 
idea (yet).

The restored height_field looks like this:

//start code
height_field {
     function 500,500 {pattern {bozo scale 0.08}}
     smooth
     translate <-0.5, 0, -0.5>
     texture {
       pigment {
         average
         pigment_map {
           [1.0 rgb <0.5, 1, 0.3>]
           [0.6 gradient x frequency 100
                color_map {
                  [0.07 rgb -0.3]
                  [0.07 rgb <0.7, 1, 0.7>]
                }
              ]
           [0.6 gradient z frequency 100
                color_map {
                  [0.07 rgb -0.3]
                  [0.07 rgb <0.7, 1, 0.7>]
                }
              ]
         }
       }
       finish {ambient 0 diffuse 0.5}
     }
     scale HF_scale
     translate -HF_scale.y*y
     scale <1, 0.5, 1>
   }
//end code

>>>
>>> As an experiment to see the effect of a changing camera angle, try this...
> 
> Well, those values are now wrong as well :-O  Although, it would still be useful
> for you to run two renders with vastly different camera angle values, to see how
> the found translation value gets more accurate at 'telephoto/zoom' settings.

I did, and the results are certainly better when using the zoom effect.

> 
> BTW, Norbert's position-finder code also #debugs the found rotation/translation
> values to the message pane. My own (Windows) set-up for *using* those values is
> to go there, then EDIT/COPY PANE, then paste the contents into Windows' Wordpad
> or Notepad. Then, I re-copy the two values and simply paste them into my scene
> code. (Instead of copying them by eye from the preview render.) It's fast and
> foolproof.
> 
> Meanwhile, I continue working...
> 

Me too...


-- 
Thomas


Post a reply to this message

From: Stephen
Subject: Re: Norbert Kern's 'Position-Finder' code-- redux
Date: 28 Sep 2018 04:12:57
Message: <5bade289$1@news.povray.org>
On 28/09/2018 07:27, Thomas de Groot wrote:
> On 27-9-2018 21:29, Stephen wrote:

>>
>> There is a nice little TRS utility called Capture2Text that selects a 
>> portion of your screen then OCR's the text and copies it to the 
>> clipboard. I find it very handy.
>>
>> http://capture2text.sourceforge.net/
>>
> 
> Thanks! That is very useful!
> 

I have been using it for a couple of years and it is probably my most 
used utility. In Pov you might need to change he message pane, font and 
size for the OCR to work properly in English. I have not tried using any 
of the other languages or translation functions.



-- 

Regards
     Stephen


Post a reply to this message

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