|
|
"Kima" <nomail@nomail> wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> > "Kima" <nomail@nomail> wrote:
> > > I try to create a tube by connecting cylinders over a spline. To avoid
> > > unnecessary elements, I want to check if three points in line to avoid creation
> > > of two cylinders when one is sufficient.
> > >
> > > To do this, I need to calculate the normalized vector of P2-P1 and compare it
> > > with that of P3-P3 using the functions given at
> > > https://www.povray.org/documentation/view/3.6.1/459/
> > >
> > > What is the most efficient way, as it is a continuous calculation, which may
> > > enable me to increase the resolution (number of points).
> >
> > You can do it like this:
> >
> >
> > #declare Nil = 1e-5; // Some small number
> >
> > #declare p1 = <2, -3, 1>;
> > #declare p2 = <-3, 4, -2>;
> > #declare p3 = <5, 0, -3>;
> > // #declare p3 = (p1 + p2)/2;
> >
> > #declare vC = vcross(p2 - p1, p3 - p1);
> >
> >
> > Now if vlength(vC) <= Nil, then the points are in line or almost in line.
> >...
> I first went for calculating vlength because it is straightforward. I then tried
> the angle between two vectors since I could set a degree of deviation.
>
> By the way, your artworks are amazing. I am playing with your python notebooks.
Thank you Kima.
I find Python much more powerful than the POV-Ray SDL when it comes to writing
code for 3D-calculations. It's a pity that the 3D rendering process is much more
involved in Python.
If p1 is "the middle" point of p1, p2 and p3 - and you have decided on a fixed
acceptable maximum angle (for using p1), then you can do this:
#declare Angle = radians(179); // Maximum angle (between 0 and Pi)
#declare Cos = cos(Angle);
// The two calculations above should only be done once.
#declare Dot = vdot(vnormalize(p2 - p1), vnormalize(p3 - p1));
#if (Dot < Cos)
// Do not use p1
#end // if
I also suggest that you write your code so that you don't have to normalize both
the two possible vectors between each pair of points as you traverse the points
on the spline.
For example, if these are points along your spline:
pA, pB, pC, pD, pE, ...
Then:
vnormalize(pB - pC) = -vnormalize(pC - pB)
vnormalize(pC - pD) = -vnormalize(pD - pC)
vnormalize(pD - pE) = -vnormalize(pE - pD)
....
--
Tor Olav
http://subcube.com
https://github.com/t-o-k
Post a reply to this message
|
|