POV-Ray : Newsgroups : povray.newusers : Intersections not quite working? Server Time
28 Jul 2024 10:16:25 EDT (-0400)
  Intersections not quite working? (Message 1 to 6 of 6)  
From: Ian K
Subject: Intersections not quite working?
Date: 16 Mar 2009 13:45:00
Message: <web.49be8fcd44abb44af8e064a80@news.povray.org>
So, I'm pretty new at this, but I'm trying to render arcs to display the angles
between bonds in molecules, using a function that takes the vectors of the
bonds and uses the intersection of two semicircular prisms to draw an acute arc
- something like this:


#macro drawAcuteArc(centre, arcSweepStart, arcSweepEnd, arcRadius, borderWidth)
  #local arcDepth = 0.1;
  #local arcNorm = vcross(arcSweepStart,arcSweepEnd);
  #local arcAngle = VRotation(arcSweepStart, arcSweepEnd, arcNorm);
  #debug "Angle = "
  #debug str(arcAngle, 0, 3)

  intersection {
    //Semicircle 1
    difference{
      cylinder{ centre - arcDepth * arcNorm, centre + arcDepth * arcNorm,
arcRadius }
      plane{ arcSweepStart, 0 translate centre }
    }

    //Semicircle 2
    difference{
      cylinder{ centre - arcDepth * arcNorm, centre + arcDepth * arcNorm,
arcRadius }
      plane{ arcSweepEnd, 0 translate centre}
    }

    pigment {rgbf <1,0,0,0>}
  }
#end

drawAcuteArc(0, <0,1,1>, <1,0,0>, 5.5, 0.5)



The only problem is that this doesn't do that. It seems to instead give me a
slice where the arc would start, and a slice where the arc would stop, and no
arc.

If I make the faces more differently placed, it seems to intersect correctly - I
tried making one of the cylinders bigger than the other, and it seemed that only
faces that were created by the intersection, rather than faces which were
coincident in the creating models, were shown. This seems a little dodgy - is
it a bug?

Thanks,
-Ian


Post a reply to this message

From: Mike Williams
Subject: Re: Intersections not quite working?
Date: 16 Mar 2009 15:21:05
Message: <FjpHeyAfaqvJFwF1@econym.demon.co.uk>
Wasn't it Ian K who wrote:
>So, I'm pretty new at this, but I'm trying to render arcs to display the angles
>between bonds in molecules, using a function that takes the vectors of the
>bonds and uses the intersection of two semicircular prisms to draw an acute arc
>- something like this:
>
>
>#macro drawAcuteArc(centre, arcSweepStart, arcSweepEnd, arcRadius, borderWidth)
>  #local arcDepth = 0.1;
>  #local arcNorm = vcross(arcSweepStart,arcSweepEnd);
>  #local arcAngle = VRotation(arcSweepStart, arcSweepEnd, arcNorm);
>  #debug "Angle = "
>  #debug str(arcAngle, 0, 3)
>
>  intersection {
>    //Semicircle 1
>    difference{
>      cylinder{ centre - arcDepth * arcNorm, centre + arcDepth * arcNorm,
>arcRadius }
>      plane{ arcSweepStart, 0 translate centre }
>    }
>
>    //Semicircle 2
>    difference{
>      cylinder{ centre - arcDepth * arcNorm, centre + arcDepth * arcNorm,
>arcRadius }
>      plane{ arcSweepEnd, 0 translate centre}
>    }
>
>    pigment {rgbf <1,0,0,0>}
>  }
>#end
>
>drawAcuteArc(0, <0,1,1>, <1,0,0>, 5.5, 0.5)
>
>
>
>The only problem is that this doesn't do that. It seems to instead give me a
>slice where the arc would start, and a slice where the arc would stop, and no
>arc.
>
>If I make the faces more differently placed, it seems to intersect
>correctly - I
>tried making one of the cylinders bigger than the other, and it seemed
>that only
>faces that were created by the intersection, rather than faces which were
>coincident in the creating models, were shown. This seems a little dodgy - is
>it a bug?

Things like that can happen with coincident surfaces.

In the general case, the workround is to displace one of the components
slightly

  #local arcDepth2 = arcDepth*1.00001;

    //Semicircle 2
    difference{
      cylinder{ centre - arcDepth2 * arcNorm, centre + arcDepth2 *
        arcNorm, arcRadius }
      plane{ arcSweepEnd, 0 translate centre}
    }


However, in this case you don't need a second cylinder. You can just
difference both planes from the same one:

#macro drawAcuteArc(centre, arcSweepStart, arcSweepEnd, arcRadius,
borderWidth)
  #local arcDepth = 0.1;
  #local arcNorm = vcross(arcSweepStart,arcSweepEnd);

  difference{
    cylinder{ centre - arcDepth * arcNorm, centre + arcDepth
       * arcNorm, arcRadius }
    plane{ arcSweepStart, 0 translate centre }
    plane{ arcSweepEnd, 0 translate centre}
    pigment {rgbf <1,0,0,0>}
   }
#end

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Mike Williams
Subject: Re: Intersections not quite working?
Date: 16 Mar 2009 15:33:05
Message: <NjlFetDvlqvJFwkA@econym.demon.co.uk>
In case you need it at some point, here's the obtuse equivalent:

#macro drawObtuseArc(centre, arcSweepStart, arcSweepEnd, arcRadius,
borderWidth)
  #local arcDepth = 0.1;
  #local arcNorm = vcross(arcSweepStart,arcSweepEnd);

  difference{
    cylinder{ centre - arcDepth * arcNorm, centre + arcDepth * arcNorm,
arcRadius }
    intersection {
      plane{ -arcSweepStart, 0 translate centre }
      plane{ -arcSweepEnd, 0 translate centre}
    }
    pigment {rgbf <1,0,0,0>}
   }
#end

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Leroy Whetstone
Subject: Re: Intersections not quite working?
Date: 16 Mar 2009 17:03:09
Message: <49BEBE37.5000805@joplin.com>
A few questions about the variable you used:
  'arcSweepStart' & 'arcSweepEnd' are they location vectors or normal 
vectors  because you use them as normals in the planes?
The way you use them if they're not pointing in the right direction 
it'll get funky.
   'centre' I'm questing would be the midpoint between two atoms.
   'arcRadius' This I'm not sure of. If your connection two atoms at 
variable distances from each other, then the radius would have to be 
calculated, so that the end points of your bond would touch both atoms.
If in your model the atoms are all equal distance the 'arcRadius' is 
redundant

Ian K wrote:
> So, I'm pretty new at this, but I'm trying to render arcs to display the angles
> between bonds in molecules, using a function that takes the vectors of the
> bonds and uses the intersection of two semicircular prisms to draw an acute arc
> - something like this:
> 
> 
> #macro drawAcuteArc(centre, arcSweepStart, arcSweepEnd, arcRadius, borderWidth)
>   #local arcDepth = 0.1;
>   #local arcNorm = vcross(arcSweepStart,arcSweepEnd);
>   #local arcAngle = VRotation(arcSweepStart, arcSweepEnd, arcNorm);
>   #debug "Angle = "
>   #debug str(arcAngle, 0, 3)
> 
>   intersection {
>     //Semicircle 1
>     difference{
>       cylinder{ centre - arcDepth * arcNorm, centre + arcDepth * arcNorm, arcRadius
}
>       plane{ arcSweepStart, 0 translate centre }
>     }
> 
>     //Semicircle 2
>     difference{
>       cylinder{ centre - arcDepth * arcNorm, centre + arcDepth * arcNorm,
> arcRadius }
>       plane{ arcSweepEnd, 0 translate centre}
>     }
> 
>     pigment {rgbf <1,0,0,0>}
>   }
> #end
> 
> drawAcuteArc(0, <0,1,1>, <1,0,0>, 5.5, 0.5)
> 
> 
> 
> The only problem is that this doesn't do that. It seems to instead give me a
> slice where the arc would start, and a slice where the arc would stop, and no
> arc.
> 
> If I make the faces more differently placed, it seems to intersect correctly - I
> tried making one of the cylinders bigger than the other, and it seemed that only
> faces that were created by the intersection, rather than faces which were
> coincident in the creating models, were shown. This seems a little dodgy - is
> it a bug?
> 
> Thanks,
> -Ian
> 
>


Post a reply to this message

From: Ian K
Subject: Re: Intersections not quite working?
Date: 16 Mar 2009 21:00:00
Message: <web.49bef5299813c63bce8107250@news.povray.org>
Mike Williams <nos### [at] econymdemoncouk> wrote:
> Things like that can happen with coincident surfaces.
>
> In the general case, the workround is to displace one of the components
> slightly
>
>   #local arcDepth2 = arcDepth*1.00001;
>
>     //Semicircle 2
>     difference{
>       cylinder{ centre - arcDepth2 * arcNorm, centre + arcDepth2 *
>         arcNorm, arcRadius }
>       plane{ arcSweepEnd, 0 translate centre}
>     }
>
>
> However, in this case you don't need a second cylinder. You can just
> difference both planes from the same one:
>
> #macro drawAcuteArc(centre, arcSweepStart, arcSweepEnd, arcRadius,
> borderWidth)
>   #local arcDepth = 0.1;
>   #local arcNorm = vcross(arcSweepStart,arcSweepEnd);
>
>   difference{
>     cylinder{ centre - arcDepth * arcNorm, centre + arcDepth
>        * arcNorm, arcRadius }
>     plane{ arcSweepStart, 0 translate centre }
>     plane{ arcSweepEnd, 0 translate centre}
>     pigment {rgbf <1,0,0,0>}
>    }
> #end

Many thanks for this, and for the obtuse form.

My original intention was to use two cylinders so that once I'd got it working,
I'd be able to use the same macro for reflex angles just by calculating the
angle and changing the 'intersection' to a 'merge', which is why the original
looks like it does. I'm now thinking it would be easier to plan to detect the
angle inside an umbrella drawArc function and then use the appropriate macro
from inside.

-Ian


Post a reply to this message

From: Ian K
Subject: Re: Intersections not quite working?
Date: 17 Mar 2009 10:45:00
Message: <web.49bfb6e19813c63bf8e064a80@news.povray.org>
Leroy Whetstone <lrw### [at] joplincom> wrote:
> A few questions about the variable you used:
>   'arcSweepStart' & 'arcSweepEnd' are they location vectors or normal
> vectors  because you use them as normals in the planes?
> The way you use them if they're not pointing in the right direction
> it'll get funky.
>    'centre' I'm questing would be the midpoint between two atoms.
>    'arcRadius' This I'm not sure of. If your connection two atoms at
> variable distances from each other, then the radius would have to be
> calculated, so that the end points of your bond would touch both atoms.
> If in your model the atoms are all equal distance the 'arcRadius' is
> redundant


This is supposed to draw arcs between molecular bonds, so if you have 3 atoms:
  1
 /
2--3

'centre' is Origin -> 2
'arcSweepStart' and 'arcSweepEnd' are 2->1 and 2->3 (doesn't matter which way
around).
'arcRadius' is there because I didn't want to draw an arc with the edge at 1 or
3, I wanted a smaller one.

I rechecked on your suggestion, and yes, I was mis-using arcSweepStart and
arcSweepEnd - I needed to rotate them about the cross product to get the proper
vectors for the plane.

My almost finished macro looks like this:

#macro drawArc2(centre, arcSweepStart, arcSweepEnd, arcRadius, borderWidth,
invertArc)
  #local arcDepth = 0.1;
  #local arcNorm = vcross(arcSweepStart,arcSweepEnd);
  #local arcAngle = VRotation(arcSweepStart, arcSweepEnd, arcNorm);
  #debug "drawArc: Arc angle = "
  #debug str(arcAngle/(2*pi/360), 0, 3)
  #debug "\n"

  #if( arcAngle = pi )
    //draw180Arc
  #else
    #local planeNormVectorStart = vaxis_rotate(arcSweepStart,arcNorm, 90);
    #local planeNormVectorEnd   = vaxis_rotate(arcSweepEnd,arcNorm, -90);

    difference{
      cylinder{ centre - 2 * arcDepth * arcNorm, centre + 2 * arcDepth *
arcNorm, arcRadius*2 }
      union{
        plane{ planeNormVectorStart, 0 translate centre }
        plane{ planeNormVectorEnd, 0 translate centre }
      #if (invertArc)
        inverse
      #end
      }
      pigment {rgbf <1,0,0,0.5>}
    }
  #end
#end

It doesn't yet handle 180 degree arcs, but that's just because I haven't decided
how to orient them yet.

And the 'invertArc' variable makes it draw the opposite angle to what it would
without.

Now to polish it off, and test it with Avogadro!

Thanks,
-Ian


Post a reply to this message

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