POV-Ray : Newsgroups : povray.newusers : Help - very difficult when it should be easy Server Time
16 Apr 2024 13:53:54 EDT (-0400)
  Help - very difficult when it should be easy (Message 11 to 19 of 19)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Trevor G Quayle
Subject: Re: Help - very difficult when it should be easy
Date: 16 Nov 2016 17:00:01
Message: <web.582cd6cdba97f5c181c811d20@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.

Actually you'd also have to check the second instance as well:
#declare RotY = degrees(atan2(Vec.z,Vec.x));
and ensure that z & x aren't the same.  If they are, then the box is vertical
and doesn't need rotation about y.

-tgq


Post a reply to this message

From: Bald Eagle
Subject: Re: Help - very difficult when it should be easy
Date: 17 Nov 2016 13:05:01
Message: <web.582df094ba97f5c1b488d9aa0@news.povray.org>
Thanks Trevor.  :)

I _almost got it.
Still a bit hairy somewhere.

Here's what I'm trying to get to work:


#version 3.7;

global_settings {assumed_gamma 1.0}

#include "colors.inc"
#include "math.inc"
#include "rand.inc"
#include "textures.inc"
#include "transforms.inc"

#declare Feet = 12;
#declare Phi = (1+sqrt(5))/2;

camera {
 location <0*Feet, 0*Feet, -500*Feet>
 look_at  <0*Feet, 0*Feet, 0>
 right     x*image_width/image_height
 up y
}

light_source {<50*Feet, 5000*Feet, 10000*Feet> Yellow} // Sun
light_source {<-100*Feet, 50*Feet, -300*Feet> White}

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 pigment
          } //end skysphere

//###########################################################################################

#declare DrawingScale = 8*Feet / 25;
#declare ArcHeight = 18*DrawingScale; // measured 18 mm on drawing
#declare ArcLength = 170*DrawingScale; // measured 17 cm (170 mm) on drawing
#declare GlobeRadius = (pow(ArcHeight,2) + pow(ArcLength,2)) / (2*ArcHeight);

#declare Scale = GlobeRadius/Phi;   // radius of sphere
#debug concat( " GlobeRadius = ", str(Scale/12, 3, 2), " feet \n")

//###########################################################################################

#declare TwentyHedron = array [12] {
<0, Phi, -1>,   // Top front    0
<0, Phi,  1>,   // Top Rear     1

<-Phi,  1, 0>,  // Left Top     2
<-Phi, -1, 0>,  // Left bottom  3

<Phi,  1,  0>,  // Right top    4
<Phi, -1,  0>,  // Right bottom 5

<-1, 0, -Phi>,  // Front left   6
< 1, 0, -Phi>,  // Front Right  7

<-1. 0, Phi>,   // Rear left   8
< 1, 0, Phi>,   // Rear right   9

<0, -Phi, -1>,  // bottom front 10
<0, -Phi,  1>,  // bottom rear  11
}

#declare IcosahedralArray = array [20][3] {
 //front top cap
    {TwentyHedron[ 0], TwentyHedron[ 4], TwentyHedron[ 1]},     //          1
    {TwentyHedron[ 0], TwentyHedron[ 7], TwentyHedron[ 4]},     //        /   \
    {TwentyHedron[ 0], TwentyHedron[ 6], TwentyHedron[ 7]},     //       2  0  4
    {TwentyHedron[ 0], TwentyHedron[ 2], TwentyHedron[ 6]},     //       \     /
    {TwentyHedron[ 0], TwentyHedron[ 1], TwentyHedron[ 2]},     //        6---7
    // middle belt
    {TwentyHedron[ 1], TwentyHedron[ 9], TwentyHedron[ 8]},
    {TwentyHedron[ 1], TwentyHedron[ 4], TwentyHedron[ 9]},
    {TwentyHedron[ 4], TwentyHedron[ 5], TwentyHedron[ 9]},
    {TwentyHedron[ 4], TwentyHedron[ 7], TwentyHedron[ 5]},     //
1---4---7---6---2---1
    {TwentyHedron[ 7], TwentyHedron[10], TwentyHedron[ 5]},     //     / \ / \ /
\ / \ / \ /
    {TwentyHedron[ 7], TwentyHedron[ 6], TwentyHedron[10]},     //
8---9---5---10--3---8
    {TwentyHedron[ 6], TwentyHedron[ 3], TwentyHedron[10]},
    {TwentyHedron[ 6], TwentyHedron[ 2], TwentyHedron[ 3]},
    {TwentyHedron[ 2], TwentyHedron[ 8], TwentyHedron[ 3]},
    {TwentyHedron[ 2], TwentyHedron[ 1], TwentyHedron[ 8]},
    //rear bottom cap
    {TwentyHedron[11], TwentyHedron[ 8], TwentyHedron[ 9]},     //        8---9
    {TwentyHedron[11], TwentyHedron[ 9], TwentyHedron[ 5]},     //       /     \
    {TwentyHedron[11], TwentyHedron[ 5], TwentyHedron[10]},     //      3   11
5
    {TwentyHedron[11], TwentyHedron[10], TwentyHedron[ 3]},     //       \     /
    {TwentyHedron[11], TwentyHedron[ 3], TwentyHedron[ 8]}      //          10
}

//
################################################################################################

#macro Subdivision (BasisArray, Iterations)

 //-----------------------------------------------------------------
 //  Subdivision of triangles
 //-----------------------------------------------------------------
 #for (Subdivide, 1, Iterations)
 #local BasisNumber = dimension_size (BasisArray, 1);
 #local ExpandedArray = array [4 * BasisNumber][3];
 //#debug "------------\n"
     #for (BasisTriangle, 0, BasisNumber-1)

 //  Subdivision scheme for triangles
 //           1
 //          / \
 //         A___B
 //        / \ / \
 //       0___C___2

 #local Vertex_A = vnormalize(
(BasisArray[BasisTriangle][0]+BasisArray[BasisTriangle][1])/2 );
 #local Vertex_B = vnormalize(
(BasisArray[BasisTriangle][1]+BasisArray[BasisTriangle][2])/2 );
 #local Vertex_C = vnormalize(
(BasisArray[BasisTriangle][2]+BasisArray[BasisTriangle][0])/2 );

 #local ExpandedArray [(4*BasisTriangle)+0][0] =
vnormalize(BasisArray[BasisTriangle][0]);
 //#local ExpandedArray [(4*BasisTriangle)+0][1] =
(BasisArray[BasisTriangle][0]+BasisArray[BasisTriangle][1])/2;
 #local ExpandedArray [(4*BasisTriangle)+0][1] = Vertex_A;
 //#local ExpandedArray [(4*BasisTriangle)+0][2] =
(BasisArray[BasisTriangle][0]+BasisArray[BasisTriangle][2])/2;
 #local ExpandedArray [(4*BasisTriangle)+0][2] = Vertex_C;

 #local ExpandedArray [(4*BasisTriangle)+1][0] =
vnormalize(BasisArray[BasisTriangle][1]);
 //#local ExpandedArray [(4*BasisTriangle)+1][1] =
(BasisArray[BasisTriangle][1]+BasisArray[BasisTriangle][0])/2;
 #local ExpandedArray [(4*BasisTriangle)+1][1] = Vertex_B;
 //#local ExpandedArray [(4*BasisTriangle)+1][2] =
(BasisArray[BasisTriangle][1]+BasisArray[BasisTriangle][2])/2;
 #local ExpandedArray [(4*BasisTriangle)+1][2] = Vertex_A;

 #local ExpandedArray [(4*BasisTriangle)+2][0] =
vnormalize(BasisArray[BasisTriangle][2]);
 //#local ExpandedArray [(4*BasisTriangle)+2][1] =
(BasisArray[BasisTriangle][2]+BasisArray[BasisTriangle][0])/2;
 #local ExpandedArray [(4*BasisTriangle)+2][1] = Vertex_C;
 //#local ExpandedArray [(4*BasisTriangle)+2][2] =
(BasisArray[BasisTriangle][2]+BasisArray[BasisTriangle][1])/2;
 #local ExpandedArray [(4*BasisTriangle)+2][2] = Vertex_B;

 //#local ExpandedArray [(4*BasisTriangle)+3][0] =
(BasisArray[BasisTriangle][0]+BasisArray[BasisTriangle][1])/2;
 #local ExpandedArray [(4*BasisTriangle)+3][0] = Vertex_A;
 //#local ExpandedArray [(4*BasisTriangle)+3][1] =
(BasisArray[BasisTriangle][1]+BasisArray[BasisTriangle][2])/2;
 #local ExpandedArray [(4*BasisTriangle)+3][1] = Vertex_B;
 //#local ExpandedArray [(4*BasisTriangle)+3][2] =
(BasisArray[BasisTriangle][2]+BasisArray[BasisTriangle][0])/2;
 #local ExpandedArray [(4*BasisTriangle)+3][2] = Vertex_C;

 /*
 #debug concat( "Vertex 0 = ", vstr(3, BasisArray[BasisTriangle][0], ", ", 3,
3), " \n")
 #debug concat( "Vertex 1 = ", vstr(3, BasisArray[BasisTriangle][1], ", ", 3,
3), " \n")
 #debug concat( "Vertex 2 = ", vstr(3, BasisArray[BasisTriangle][2], ", ", 3,
3), " \n")
 #debug concat( "Vertex A = ", vstr(3, Vertex_A, ", ", 3, 3), " \n")
 #debug concat( "Vertex B = ", vstr(3, Vertex_B, ", ", 3, 3), " \n")
 #debug concat( "Vertex C = ", vstr(3, Vertex_C, ", ", 3, 3), " \n")
 #debug "------------\n\n"
 */

 #end // end for BasisTriangle
 #local BasisArray = ExpandedArray;
#end // end for Subdivide

ExpandedArray

#end // end macro subdivision


//
################################################################################################

// Build Globe for Scene

#declare Globe_Array = Subdivision (IcosahedralArray, 4)  //  <=================
perform expansion of icosahedraal basis array
#declare ExpandedNumber = dimension_size (Globe_Array, 1);

 #for (Side, 0, ExpandedNumber-1)
  #for (Vertex, 0, 2)
   #declare Globe_Array[Side][Vertex] = Globe_Array[Side][Vertex] * Scale;
  #end // end for Vertex
 #end // end for Side

#declare Strut = 5;
#declare GlobeColor = pigment {Green*0.5}

//  Cylinder Mesh (as guide) and Struts
#declare MeshSphere_1 =
union {
 #declare LastVertex = <0, 0, 0>;

 #for (Side, 0, ExpandedNumber-1)
     #for (Vertex, 0, 2)
   #declare ThisVertex = Globe_Array[Side][Vertex];
   //#debug concat( "Vertex = ", vstr(3, ExpandedArray[Side][Vertex], ", ", 3,
3), " \n")

   #if (Vertex > 0)
    cylinder {LastVertex, ThisVertex, Strut/4 texture {pigment {GlobeColor}
finish {specular 0.8}} }
    #declare CurrentVector = (ThisVertex - LastVertex);

//--------------------------------------------------------------------------------------------------
      // #declare Vec = Point2 - Point1;       //Direction vector to orient to
      #declare Vec = (ThisVertex - LastVertex);
      #declare StrutLength = vlength(CurrentVector);  //LENGTH OF BOX
    //Twist rotates the box around the long axis first
    #declare Twist = 0;
      //RotZ and RotY reoorient the box to align to the vector
      #if (StrutLength = 0 | Vec.x = 0 | Vec.z = 0)
       // do nothing
      #else
       #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 = union {
      box {<0, -Strut, -Strut/3>, <StrutLength, -Strut*0.9, Strut/3>}
      box {<0, -Strut, -Strut/2>, <StrutLength,  Strut,     Strut/2>}
      box {<0,  Strut, -Strut/3>, <StrutLength,  Strut*0.9, Strut/3>}
      pigment {Red*0.5}
     } // end IBeam

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

     object {NewIBeam translate ThisVertex}
    #end // end if (atan2 check)
   #end // end if (past 1st triangle point)

   #declare LastVertex = ThisVertex;
  #end // end for Vertex



   cylinder {LastVertex, Globe_Array[Side][0], Strut/4 texture {pigment
{GlobeColor} finish {specular 0.8}} }
   #declare CurrentVector = (Globe_Array[Side][0] - LastVertex);

//--------------------------------------------------------------------------------------------------
    // #declare Vec = Point2 - Point1;       //Direction vector to orient to
    #declare Vec = (ThisVertex - LastVertex);
    #declare StrutLength = vlength(CurrentVector);  //LENGTH OF BOX
   //Twist rotates the box around the long axis first
   #declare Twist = 0;
    //RotZ and RotY reoorient the box to align to the vector
    #if (StrutLength = 0 | Vec.x = 0 | Vec.z = 0)
     // do nothing
    #else
      #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 = union {
     box {<0, -Strut, -Strut/3>, <StrutLength, -Strut*0.9, Strut/3>}
     box {<0, -Strut, -Strut/2>, <StrutLength,  Strut,     Strut/2>}
     box {<0,  Strut, -Strut/3>, <StrutLength,  Strut*0.9, Strut/3>}
     pigment {Red*0.6}
    } // end IBeam

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

    object {NewIBeam translate ThisVertex}
   #end // end if (atan2 check)
 #end // end for Side

} // end union MeshSphere_1


#declare Globe = union {
 object {MeshSphere_1}   // Struts

 #declare Axes = 12;
 cylinder {<0, 0, 0>, <200*Feet, 0, 0> Axes pigment {Red*0.5}}
 cylinder {<0, 0, 0>, <0, 200*Feet, 0> Axes pigment {Green*0.5}}
 cylinder {<0, 0, 0>, <0, 0, 200*Feet> Axes pigment {Blue*0.5}}
}


object {Globe}


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Help - very difficult when it should be easy
Date: 20 Nov 2016 22:30:01
Message: <web.58326a12ba97f5c179917fa00@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "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.)

No, points and vectors are not the same thing:

- You can add a vector to a vector and get a vector
- You can subtract a vector from a vector and get a vector
- You can subtract a point from a point and get a vector
- You can add a vector to a point and get a point
- You can subtract a vector from a point and get a point
- But you can not add a point to a point

(If you insist on adding points, I suggest that you read about barycentric
coordinates.)


> 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


Does this code do what you want ?
(Replace your for loop and everything within it with this code.)


#macro ProjectToPlane(v0, vN)

   (v0 - vdot(v0, vN)/vdot(vN, vN)*vN)

#end // macro ProjectToPlane


#for (Test, 0, 4)

  #declare p1 = StartArray[Test];
  #declare p2 = EndArray[Test];
  #declare v12 = p2 - p1;
  #declare StrutLength = vlength(v12);

  sphere {
    p1, 0.5
    pigment { Orange }
  }
  cylinder {
    p1, p2, Strut/2*1.05
    pigment { Cyan }
  }
  sphere {
    p2, 0.5
    pigment { Violet }
  }

  #declare vXZ = ProjectToPlane(v12, y);
  #declare TransformA = Reorient_Trans(x, vXZ)
  #declare TransformB = Reorient_Trans(vXZ, v12)
  #declare TotalTransform =
    transform {
      transform TransformA
      transform TransformB
      translate p1
    }
  box {
    <0, -Strut/2, -Strut/2>, <StrutLength, Strut/2, Strut/2>
    transform { TotalTransform }
    pigment { Gray }
  }
/*
  #declare pXZ = p1 + vXZ;
  union {
    cylinder { p1, pXZ, 0.1 }
    sphere { pXZ, 0.2 }
    cylinder { pXZ, p2, 0.1 }
    pigment { Blue }
  }
*/

#end // for


--
Tor Olav
http://subcube.com


Post a reply to this message

From: Bald Eagle
Subject: Re: Help - very difficult when it should be easy
Date: 21 Nov 2016 08:00:01
Message: <web.5832ef06ba97f5c1c437ac910@news.povray.org>
I think I figured it out.
At first I thought there might be a problem with the quadrant / sector that the
calculation was done in, then it seemed like it might be anything with a Vec
with a negative x component (because the Strut object is constructed in the +x
direction).

After doing some other simplified experiments, it looks like I need to rotate in
the -y direction.   Perhaps due to the left-handed coordinate system?
Can anyone confirm?

Aside from that, I needed to translate to LastVertex (Point1) rather than
ThisVertex (Point2)

and if Twist is set to -y*RotY, then the Struts follow the spherical curvature
as desired.


Looks like it was a busy weekend here at news.povray.org
I'm glad I got some much needed rest AND (perhaps because of that) unraveled the
whole spherical trigonometry vector rotation translation spaghetti.   :)


Post a reply to this message

From: Cousin Ricky
Subject: Re: Help - very difficult when it should be easy
Date: 21 Nov 2016 12:45:01
Message: <web.5833324eba97f5c1b99945e00@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> No, points and vectors are not the same thing:
>
> - You can add a vector to a vector and get a vector
> - You can subtract a vector from a vector and get a vector
> - You can subtract a point from a point and get a vector
> - You can add a vector to a point and get a point
> - You can subtract a vector from a point and get a point
> - But you can not add a point to a point

Whoa, you have a point (no pun intended), but this will throw a monkey wrench
into my Hungarian-like notation.  ('p' is already taken by pigment.)


Post a reply to this message

From: Bald Eagle
Subject: Re: Help - very difficult when it should be easy
Date: 21 Nov 2016 13:00:00
Message: <web.583335c8ba97f5c1c437ac910@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:

> > ("point", "axis", "vector" ...   sure.   They're all the same thing.)
>
> No, points and vectors are not the same thing:


> Does this code do what you want ?
> (Replace your for loop and everything within it with this code.)


I missed this in the flurry of weekend posts - Thanks for taking the time to
look this over and offer some fully-coded solutions!
It's VERY much appreciated.

I'll paste it into my scene and give it a go.  I always like to explore multiple
methods of accomplishing the same task - they are often different in small ways
that make one particular way well suited to solving a problem in the future.

Thanks as always for your help and expertise!

PS.  Any ideas why the degrees(atan2()) results need to be sign-inverted?
IS it the left hand coordinate system that POV-Ray uses?


Post a reply to this message

From: clipka
Subject: Re: Help - very difficult when it should be easy
Date: 21 Nov 2016 13:41:40
Message: <58333fe4$1@news.povray.org>
Am 21.11.2016 um 18:43 schrieb Cousin Ricky:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
>> No, points and vectors are not the same thing:
>>
>> - You can add a vector to a vector and get a vector
>> - You can subtract a vector from a vector and get a vector
>> - You can subtract a point from a point and get a vector
>> - You can add a vector to a point and get a point
>> - You can subtract a vector from a point and get a point
>> - But you can not add a point to a point
> 
> Whoa, you have a point (no pun intended), but this will throw a monkey wrench
> into my Hungarian-like notation.  ('p' is already taken by pigment.)

Maybe it helps that "points" can also be referred to as "location
vectors", in that they specify the vector between the coordinate origin
and the point in question.


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Help - very difficult when it should be easy
Date: 23 Nov 2016 12:20:01
Message: <web.5835ce8eba97f5c1468fc97e0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
>
> > > ("point", "axis", "vector" ...   sure.   They're all the same thing.)
> >
> > No, points and vectors are not the same thing:
>
>
> > Does this code do what you want ?
> > (Replace your for loop and everything within it with this code.)
>
>
> I missed this in the flurry of weekend posts - Thanks for taking the time to
> look this over and offer some fully-coded solutions!
> It's VERY much appreciated.
>
> I'll paste it into my scene and give it a go.  I always like to explore multiple
> methods of accomplishing the same task - they are often different in small ways
> that make one particular way well suited to solving a problem in the future.

I hope my code worked for you.


> Thanks as always for your help and expertise!

You are welcome. I'm glad to help.


> PS.  Any ideas why the degrees(atan2()) results need to be sign-inverted?
> IS it the left hand coordinate system that POV-Ray uses?

I have not look at the Trevors code, so I don't know.

Generally, the rotation direction around an axis in a left handed coordinate
system is opposite of the rotation direction around an axis in a right handed
coordinate system.

But I think that you should not have to use any atan-functions to solve your
problem.

--
Tor Olav
http://subcube.com


Post a reply to this message

From: Cousin Ricky
Subject: Re: Help - very difficult when it should be easy
Date: 25 Nov 2016 21:25:00
Message: <web.5838f1dfba97f5c1b99945e00@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 21.11.2016 um 18:43 schrieb Cousin Ricky:
> > "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> >> No, points and vectors are not the same thing:
> >>
> >> [snip]
> >
> > Whoa, you have a point (no pun intended), but this will throw a monkey wrench
> > into my Hungarian-like notation.  ('p' is already taken by pigment.)
>
> Maybe it helps that "points" can also be referred to as "location
> vectors", in that they specify the vector between the coordinate origin
> and the point in question.

Then 'lv' it is!  :-)


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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