POV-Ray : Newsgroups : povray.general : How to check if three points are in line? Server Time
31 Oct 2024 16:16:41 EDT (-0400)
  How to check if three points are in line? (Message 1 to 10 of 10)  
From: Kima
Subject: How to check if three points are in line?
Date: 5 Jun 2020 14:55:01
Message: <web.5eda940f9cbbc66decc0fada0@news.povray.org>
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).


Post a reply to this message

From: Kima
Subject: Re: How to check if three points are in line?
Date: 5 Jun 2020 16:45:01
Message: <web.5edaaec1e3705a85ecc0fada0@news.povray.org>
"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).

I forgot to add that I do this VAngle(V1, V2). My question was mostly about the
general idea. If it is feasible or I've missed an emerging issue since I have
not seen such an approach in the tutorials.


Post a reply to this message

From: Bald Eagle
Subject: Re: How to check if three points are in line?
Date: 5 Jun 2020 17:45:05
Message: <web.5edabc82e3705a85fb0b41570@news.povray.org>
I'd say try utilizing this:
https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line#Line_defined_by_two_points

and checking if it's <= some small value (0.000001)

Otherwise maybe investigate what they have in the Graphics Gems series.



Did you see:

http://news.povray.org/povray.general/message/%3Cweb.5e97c81e9447013fb0b41570%40news.povray.org%3E/#%3Cweb.5e97c81e9447
013fb0b41570%40news.povray.org%3E

http://news.povray.org/povray.binaries.images/message/%3Cweb.5e97c744fd34edcfb0b41570%40news.povray.org%3E/#%3Cweb.5e97
c744fd34edcfb0b41570%40news.povray.org%3E

?


Post a reply to this message

From: Kima
Subject: Re: How to check if three points are in line?
Date: 5 Jun 2020 18:05:01
Message: <web.5edac064e3705a85ecc0fada0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:

> Did you see:
>
>
http://news.povray.org/povray.general/message/%3Cweb.5e97c81e9447013fb0b41570%40news.povray.org%3E/#%3Cweb.5e97c81e94
47
> 013fb0b41570%40news.povray.org%3E
>
>
http://news.povray.org/povray.binaries.images/message/%3Cweb.5e97c744fd34edcfb0b41570%40news.povray.org%3E/#%3Cweb.5e
97
> c744fd34edcfb0b41570%40news.povray.org%3E
>
> ?

NO! How did I miss it? I re-checked the curved prism thread, but still, I
couldn't find it.

How did you make it? I am very much interested in any alteration of prism :)


Post a reply to this message

From: Bald Eagle
Subject: Re: How to check if three points are in line?
Date: 5 Jun 2020 19:55:00
Message: <web.5edada4ce3705a85fb0b41570@news.povray.org>
"Kima" <nomail@nomail> wrote:

> NO! How did I miss it? I re-checked the curved prism thread, but still, I
> couldn't find it.
>
> How did you make it? I am very much interested in any alteration of prism :)

You should visit more and post some renders of your work(s) in progress and
completed projects.

;)     ;)     ;)     ;)     ;)     ;)     ;)     ;)     ;)     ;)     ;)     ;)



It's a prism topped with an isosurface that blends from a polygon function to a
sphere over a range in y.

It took forever to get it right, and it's not exactly generally applicable.

But that's the kind of shape you were looking for, right?


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: How to check if three points are in line?
Date: 5 Jun 2020 23:15:00
Message: <web.5edb0964e3705a856d7cc5a50@news.povray.org>
"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.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k/


Post a reply to this message

From: kurtz le pirate
Subject: Re: How to check if three points are in line?
Date: 6 Jun 2020 04:03:41
Message: <5edb4ddd$1@news.povray.org>
On 06/06/2020 05:12, Tor Olav Kristensen wrote:

> #declare vC = vcross(p2 - p1, p3 - p1);
> 
> 
> Now if vlength(vC) <= Nil, then the points are in line or almost in line.

Wholeheartedly agree.
If cross product of two vectors is null, the points are aligned.
Just be careful about 'null' value.




-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

From: Kima
Subject: Re: How to check if three points are in line?
Date: 6 Jun 2020 07:35:01
Message: <web.5edb7f53e3705a85ecc0fada0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Kima" <nomail@nomail> wrote:
>
> > NO! How did I miss it? I re-checked the curved prism thread, but still, I
> > couldn't find it.
> >
> > How did you make it? I am very much interested in any alteration of prism :)
>
> You should visit more and post some renders of your work(s) in progress and
> completed projects.
>
> ;)     ;)     ;)     ;)     ;)     ;)     ;)     ;)     ;)     ;)     ;)     ;)
>
>
>
> It's a prism topped with an isosurface that blends from a polygon function to a
> sphere over a range in y.
>
> It took forever to get it right, and it's not exactly generally applicable.
>
> But that's the kind of shape you were looking for, right?

You're right, I should come more often, as subtle tricks are introduced here.

My projects are more for fun as a hobby. Thus, there is no straight line to
measure progress. So, I easily give up an idea and try another; but I frequently
check for emerging solutions for my older ideas :)

isosurface is very flexible, but I was unable to find a pragmatic way to match
it with prism. Theoretically, it is possible, as the points and curves of the
prim can be easily calculated through the underlying spline. Unless the prism
shape is geometrical to find a matching isosurface function.


Post a reply to this message

From: Kima
Subject: Re: How to check if three points are in line?
Date: 6 Jun 2020 08:25:01
Message: <web.5edb8ab7e3705a85ecc0fada0@news.povray.org>
"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.
>
> --
> Tor Olav
> http://subcube.com
> https://github.com/t-o-k/

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.


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: How to check if three points are in line?
Date: 8 Jun 2020 11:35:01
Message: <web.5ede59dfe3705a854bb18d5a0@news.povray.org>
"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

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