POV-Ray : Newsgroups : povray.advanced-users : Divide by zero : Re: Divide by zero Server Time
28 Sep 2024 18:53:38 EDT (-0400)
  Re: Divide by zero  
From: Le Forgeron
Date: 19 Jul 2010 14:04:01
Message: <4c449391$1@news.povray.org>
Le 19/07/2010 19:44, stbenge nous fit lire :
> Hello,
> 
> In one of my macros, I'm finding the slope of a 2D line, and sometimes I
> get that warning about dividing by zero. Since it seems that diving any
> number by zero results in an infinite number, would something like this
> be a good fix?
> 
> #if(A.x-B.x != 0)
>  #local m1 = (A.y-B.y)/(A.x-B.x);
> #else
>  #local m1 = 1e10;
> #end
> 
> It seems to get rid of the warnings, but I wonder if there's a better way.
> 
> This poor hack was (understandably) giving me artifacts:
> 
> (A.x-B.x+0.000001)
> 
> I guess the other option is to jitter my points slightly, but that would
> introduce problems into the whole setup, and total infallibility would
> still not be ensured.

Why do you need the sloperate of your 2D line ?
why not computing the angle of the slope instead, using atan2 ?
With the angle instead of the slope, no more issue with vertical line.

(atan2() result would be in radian, just in case you would be wondering)


Post a reply to this message

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