A
A
Alexander2016-03-10 12:27:08
JavaScript
Alexander, 2016-03-10 12:27:08

How do you know if a point falls on a diagonal line?

So far I've come up with this, but it doesn't work correctly.

var x1 = 10
var y1 = 10
var x2 = 500
var y2 = 400
// ...
var a = (x2 - x1) / (y2 - y1)
// ...
var x = mouseX - x1
var y = mouseY - y1
var isLine = (x > 0 && y > 0) 
           && Math.abs(a - x / y) / < 0.5
            && x < (x2 - x1)
            && y < (y2 - y1);

Unfortunately, I can't find the answer through search.
Tell me please.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question