POV-Ray : Newsgroups : povray.general : How to check if three points are in line? : Re: How to check if three points are in line? Server Time
24 Apr 2024 18:07:03 EDT (-0400)
  Re: How to check if three points are in line?  
From: Tor Olav Kristensen
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

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