|
|
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
|
|