POV-Ray : Newsgroups : povray.newusers : Help - very difficult when it should be easy Server Time
21 Dec 2024 08:23:29 EST (-0500)
  Help - very difficult when it should be easy (Message 1 to 10 of 19)  
Goto Latest 10 Messages Next 9 Messages >>>
From: Bald Eagle
Subject: Help - very difficult when it should be easy
Date: 16 Nov 2016 10:15:00
Message: <web.582c7706cc24aa88b488d9aa0@news.povray.org>
Posting this in PNU since it seems like it ought to be a simple task, and
probably one that would be commonly used if it was.

I think this also touches on the discussion of what can be done to help make POV
better and more accessible to new users, to help them start using POV as a
tool-of-choice, rather than something to be avoided and abandoned out of
frustration.

The transform {} command was pretty confusing to implement - it's one of those
things where it seems like you're layering the same command, and it was sort of
hard to grasp how to go from transforming values to applying that transform to
an object.  I can appreciate how such a thing could be a stumbling block for a
new user unaccustomed to POV-Ray's SDL command structure.  [A big thank you to
all who have helped me learn the ins and outs of coding complex scenes!]

Now to the task at hand:
------------------------

I'm trying to extend the ends of a box object between 2 points - mimicking a
cylinder.
I naively tried the VRotationD macro in math.inc, and then discovered my error
of trying to simply rotate around Z after rotating around Y upon further
extended thought.  Rotating around Y now requires rotation around some new
non-cardinal axis which I designate as Q.

I have a range of points that all work, when I just change the endpoint y, but
when I change either x or z in the same fashion, all hell breaks loose.
Is this another erroneous implementation on my part?

Also,

While working on this, I also noticed that there was a lot of stuff commented
out in the math.inc file - I'm wondering why, and if all that stuff should still
be there. Perhaps it's time to take a look through some of those macros, update
the code (if necessary), and add some clarifying comments.

Especially useful would be a new directory in the Insert Menu with practical
examples for usage, or at least a few lines of fully working code in the include
file itself that could be cut and pasted directly into a scene.


=====================================================================

// test code for aligning a box between two vectors (points)
// Bald Eagle 2016

#version 3.7;
global_settings {
 assumed_gamma 1.0
 ambient_light color rgb <1, 1, 1>
}
include "colors.inc"
include "math.inc"
include "transforms.inc"

#declare Camera_Origin = camera {
                            location  <0, 0, 0>
                            right    x*image_width/image_height
                            look_at   <0, 0, 0.01>}

#declare Camera_Angle = camera {
                            location  <10, 10, 5>
                            right    x*image_width/image_height
                            look_at   <5, 5, 5>}
#declare Camera_Front = camera {
                            location  <5, 5, -20.0>
      //location  <0.0, 12, -10.0>
                            right    x*image_width/image_height
                            look_at   <5, 5, 0>}
#declare Camera_Rear = camera {
                            location  <0.0, -100.0, -300.0>
                            right    x*image_width/image_height
                            look_at   <0, 0, 0>}
#declare Camera_Top = camera {
                            location  <5, 25.0, 5>
                            right    x*image_width/image_height
                            look_at   <5, 0, 5>}

#declare Camera_Iso = camera {
                            location  <-50, 0, 0>
                            right    x*image_width/image_height
                            look_at   <0, 0, 0>}

//####################
//camera {Camera_Front}
//camera {Camera_Top}
#declare Fraction = 8;
  //#declare Camera_Position = <5, 25, 5> ;  // top view
  #declare Camera_Position = <5, 5, -30> ;  // front view
  //#declare Camera_Position = <25, 5, 5> ;  // right view
  #declare Camera_Look_At  = <5, 5, 5> ;

camera {
   orthographic
   right     x*image_width/(2*Fraction)
   up   y*image_height/(2*Fraction)
  location  Camera_Position
  look_at   Camera_Look_At
}
//####################


light_source{ <10, 50, -50>  color rgb <1, 1, 1>}    // White top

// Create an infinite sphere around scene and allow any pigment on it
sky_sphere{ pigment { gradient <0,1,0>
                      color_map { [0.00 rgb <0.6,0.7,1.0>]
                                  [0.35 rgb <0.0,0.1,0.8>]
                                  [0.65 rgb <0.0,0.1,0.8>]
                                  [1.00 rgb <0.6,0.7,1.0>]
                                }
                      scale 2
                    } // end of pigment
          } //end of skysphere -------------------------------------


//#declare Point1 = <5, 5, 5>;
//#declare Point2 = <10, 10, 10>;

#declare DataSet = 3;

#switch (DataSet)

#case(0)
#declare StartArray = array [5] {
<5, 5, 5>,
<1, 4, 9>,
<-10, 7, -3>,
<6, 3, 9>,
<4, -8, 0>}

#declare EndArray = array [5] {
<10, 10, 10>,
<-6, 12, 3>,
<-5, 2, -8>,
<12, -10, 12>,
<-5, -4, 10>}
#break

#case(1)
#declare StartArray = array [5] {
<5, 5, 5>,
<5, 5, 5>,
<5, 5, 5>,
<5, 5, 5>,
<5, 5, 5>}

#declare EndArray = array [5] {
<10, 10, 10>,
<10, 7, 10>,
<10, 4, 10>,
<10, 1, 10>,
<10, -2, 10>}
#break

#case(2)
#declare StartArray = array [5] {
<5, 5, 5>,
<5, 5, 5>,
<5, 5, 5>,
<5, 5, 5>,
<5, 5, 5>}

#declare EndArray = array [5] {
<10, 10, 10>,
<10, 7, 7>,
<10, 4, 4>,
<10, 1, 1>,
<10, -2, -2>}
#break

#case(3)
#declare StartArray = array [5] {
<5, 5, 5>,
<5, 5, 5>,
<5, 5, 5>,
<5, 5, 5>,
<5, 5, 5>}

#declare EndArray = array [5] {
<10, 10, 10>,
<7, 7, 10>,
<4, 4, 10>,
<1, 1, 10>,
<-2, -2, 10>}
#break

#end

#declare Strut = 0.5;
#declare Axes = 0.2;

sphere {<0, 0, 0> 0.5 pigment {Gray50} }
cylinder {<0, 0, 0>, <10, 0, 0> Axes pigment {Red*0.5}}
cylinder {<0, 0, 0>, <0, 10, 0> Axes pigment {Green*0.5}}
cylinder {<0, 0, 0>, <0, 0, 10> Axes pigment {Blue*0.5}}


#for (Test, 0, min(dimension_size (StartArray, 1), dimension_size (EndArray,
1))-1 )


#debug concat( " Test = ", str(Test, 3, 1), "\n")


#declare Point1 = StartArray [Test];
#declare Point2 = EndArray [Test];

#declare StrutLength = vlength(Point2 - Point1);
#declare IBeam = box {<0, -Strut/2, -Strut/2>, <StrutLength, Strut/2, Strut/2>}
sphere {Point1 0.5 pigment {Orange*0.5} }
sphere {Point2 0.5 pigment {Violet*0.5} }

cylinder {Point1, Point2, Strut/2 texture {pigment {White} finish {specular
0.8}} }
#declare CurrentVector = (Point2 - Point1);

//--------------------------------------------------------------------------------------------------
#declare CurrentVectorX = VProject_Plane (CurrentVector, <1, 0, 0>); // x is
normal to the z-y plane
#declare CurrentVectorY = VProject_Plane (CurrentVector, <0, 1, 0>); // y is
normal to the x-z plane
#declare CurrentVectorZ = VProject_Plane (CurrentVector, <0, 0, 1>); // z is
normal to the x-y plane

#declare XDeg = VRotationD(<StrutLength, 0, 0>, CurrentVectorX, <1, 0, 0>);

#declare YDeg = VRotationD(<StrutLength, 0, 0>, CurrentVectorY, <0, 1, 0>);

#declare YTransform = transform { rotate y*YDeg };
#declare YRotated = vtransform (<StrutLength, 0, 0>, YTransform);

#declare PivotAxis = VPerp_To_Plane(YRotated, Point2);
#declare QDeg = VRotationD(YRotated, CurrentVector, PivotAxis);

#declare QTransform = transform { Axis_Rotate_Trans(PivotAxis, QDeg) };
#declare NewIBeam = object {IBeam rotate x*XDeg transform YTransform transform
QTransform};
//--------------------------------------------------------------------------------------------------

cylinder {0, PivotAxis, Strut/2 translate Point1 texture {pigment {Gray50}
finish {specular 0.8}} }
//object {IBeam rotate z*ZDeg translate Point1 pigment {Blue} }
object {IBeam translate Point1 pigment {rgbt <1, 0, 0, 0.8>} }
object {IBeam transform YTransform translate Point1 pigment {Green} }

object {NewIBeam translate Point1 pigment {Red} }

#end // end for Test


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Help - very difficult when it should be easy
Date: 16 Nov 2016 10:41:27
Message: <582c7e27@news.povray.org>
On 16.11.2016 16:11, Bald Eagle wrote:

> I'm trying to extend the ends of a box object between 2 points - mimicking a
> cylinder.

Note this is not a well-defined problem since there is freedom
of rotation along the axis between the two points. This can make
it harder to find the desired solution since attempts to solve
the generic case with math breaks down without further input.


Post a reply to this message

From: Bill Pragnell
Subject: Re: Help - very difficult when it should be easy
Date: 16 Nov 2016 11:00:01
Message: <web.582c8156ba97f5c15b7d07940@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I'm trying to extend the ends of a box object between 2 points - mimicking a
> cylinder.

Are you trying to keep the box 'upright' - rotating it around y before tilting
it out of plane, like a ramp? If so, you could use Reorient_Trans() twice on
them to keep it simple... it's in transforms.inc (which I see you're using
already).

Bill


Post a reply to this message

From: Bald Eagle
Subject: Re: Help - very difficult when it should be easy
Date: 16 Nov 2016 12:10:00
Message: <web.582c9230ba97f5c1b488d9aa0@news.povray.org>
Christian Froeschlin <chr### [at] chrfrde> wrote:

> Note this is not a well-defined problem since there is freedom
> of rotation along the axis between the two points. This can make
> it harder to find the desired solution since attempts to solve
> the generic case with math breaks down without further input.

Correct.  I have a plan for my end scene, where I can probably extract normals
from those endpoints and so orient the boxes so a flat side is out.

I figured the rotation around that final axis may be object-specific depending
on what a user might want to orient and why.  But the first step was to get the
bounding box moved so that the face centers were coincident with the desired
endpoints.


Post a reply to this message

From: Bald Eagle
Subject: Re: Help - very difficult when it should be easy
Date: 16 Nov 2016 12:35:00
Message: <web.582c9795ba97f5c1b488d9aa0@news.povray.org>
"Bill Pragnell" <bil### [at] hotmailcom> wrote:

> Are you trying to keep the box 'upright' - rotating it around y before tilting
> it out of plane, like a ramp?

Sure - that works for me.

If so, you could use Reorient_Trans() twice on
> them to keep it simple... it's in transforms.inc (which I see you're using
> already).

("point", "axis", "vector" ...   sure.   They're all the same thing.)

Here's what I tried - still no joy.

1. define a transform which is a y - rotation, the magnitude of which was
determined by projecting Point 2 onto the x-z plane [see prior code]

2. rotate my "x-axis vector" around y by this transform

3. define a transform that rotates x to the new y-rotated position

4. define a transform that rotates YRotated vector up to Point2, which as we
know, is a point, a vector, and an axis

5. apply both transforms to the object




#declare YTransform = transform { rotate y*YDeg };
#declare YRotated = vtransform (<StrutLength, 0, 0>, YTransform);

#declare NewTransform1 = transform { Reorient_Trans(x, YRotated) };
#declare NewTransform2 = transform { Reorient_Trans(YRotated, Point2) };

#declare NewIBeam = object {IBeam transform NewTransform1 transform
NewTransform2};


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Help - very difficult when it should be easy
Date: 16 Nov 2016 13:28:31
Message: <582ca54f$1@news.povray.org>
How about

#declare Rotation = Reorient_Trans(<StrutLength, 0, 0>, CurrentVector)
#declare NewIBeam = object {IBeam transform Rotation}


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Help - very difficult when it should be easy
Date: 16 Nov 2016 13:32:12
Message: <582ca62c$1@news.povray.org>
Just for a first test of course to control orientation
of box later it is not ideal.


Post a reply to this message

From: Trevor G Quayle
Subject: Re: Help - very difficult when it should be easy
Date: 16 Nov 2016 13:35:01
Message: <web.582ca614ba97f5c181c811d20@news.povray.org>
To do this I usually just use some basic trig and reorient one axis at a time.

The box is made along the x-axis, so first rotation is to apply a twist about
that x-axis if you want it, otherwise it remains upright through rotations.

Next rotation is to rotate away from the x-z plane by rotating around the
z-axis.
Final rotation is to rotate to final position around the vertical y-axis.



Just the #for Loop portion:

#for (Test, 0, min(dimension_size (StartArray, 1), dimension_size
(EndArray,1))-1 )

  #debug concat( " Test = ", str(Test, 3, 1), "\n")

  #declare Point1 = StartArray [Test];
  #declare Point2 = EndArray [Test];

  #declare Vec = Point2 - Point1;       //Direction vector to orient to
  #declare StrutLength = vlength(Vec);  //LENGTH OF BOX

  //Twist rotates the box around the long axis first
  #declare Twist = 45;

  //RotZ and RotY reoorient the box to align to the vector
  #declare RotZ = degrees(atan2(Vec.y,vlength(<Vec.x,0,Vec.z>)));  //ROTATION
ABOUT Z-AXIS
  #declare RotY = degrees(atan2(Vec.z,Vec.x));                     //ROTATION
ABOUT Y-AXIS

  #declare IBeam = box {<0, -Strut/2, -Strut/2>, <StrutLength, Strut/2,
Strut/2>}

  sphere {Point1 0.5 pigment {Orange*0.5} }
  sphere {Point2 0.5 pigment {Violet*0.5} }

  #declare NewIBeam =
    object {
      IBeam
      rotate Twist*x
      rotate RotZ*z
      rotate RotY*y
      translate Point1
    }

  object {NewIBeam pigment {Blue} }

#end // end for Test


Post a reply to this message

From: Bald Eagle
Subject: Re: Help - very difficult when it should be easy
Date: 16 Nov 2016 15:25:00
Message: <web.582cbf98ba97f5c1b488d9aa0@news.povray.org>
That looks good when I run your code - when I let it rip on a big array of
triangular coordinates, I get a "Domain error in atan2()"

I'll study your code and try to track down the cause.  Probably
degenerate/coincident points or something.


Post a reply to this message

From: Trevor G Quayle
Subject: Re: Help - very difficult when it should be easy
Date: 16 Nov 2016 17:00:01
Message: <web.582cd625ba97f5c181c811d20@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> That looks good when I run your code - when I let it rip on a big array of
> triangular coordinates, I get a "Domain error in atan2()"
>
> I'll study your code and try to track down the cause.  Probably
> degenerate/coincident points or something.

Yes, it looks like that will happen when both numbers in the atan2 function are
0.  If only one is 0, it is fine.  A simple check on the StrutLength and bypass
when it is 0 should suffice.

-tgq


Post a reply to this message

Goto Latest 10 Messages Next 9 Messages >>>

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