POV-Ray : Newsgroups : povray.newusers : Help - very difficult when it should be easy : Re: Help - very difficult when it should be easy Server Time
29 Apr 2024 16:23:08 EDT (-0400)
  Re: Help - very difficult when it should be easy  
From: Tor Olav Kristensen
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

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