0

I'm not a programmer primarily, so this might be a simple answer.

I'm working on a script in Illustrator where you select three points and then it does stuff. First it makes a triangle. Then, it recreates two of the line segments in the triangle and rotates them 90 degrees. Then, I find the intersect of those points so that I can make a circumcircle.

I'm actually moving along quite well, but the only problem I don't know how to solve at the moment is when two points that comprise the triangle have the same y-coordinates. When I make the perpendicular line, that line is vertical and therefore has no slope. It throws an error.

How do I account for a vertical slope with JavaScript? I was thinking about something along the lines of, "if the slope is NaN, then set the slope value to 9999999" or something like that, but this seemed a bit crude. Any better options?

Brendan
  • 868
  • 1
  • 16
  • 38

1 Answers1

0

You could normalise your gradient in the range -1 to 1. Anything larger than 1, or a NaN, is clamped at 1. The same goes for negative numbers, but with -1.

Bojangles
  • 99,427
  • 50
  • 170
  • 208
  • I don't doubt your answer, but I've never encountered the concept of normalization before. Do you know of a resource that explains it? – Brendan Oct 02 '12 at 18:04
  • I've just had a quick look around, and can't seem to find anything. The basic principle is taking your input range and scaling it so that the largest number becomes 1, and the smallest becomes -1 (or 0 if you don't need negative numbers). – Bojangles Oct 03 '12 at 07:47