Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Math - Get x & y coordinates at intervals along a line

I'm trying to get x and y coordinates for points along a line (segment) at even intervals. In my test case, it's every 16 pixels, but the idea is to do it programmatically in ActionScript-3.

I know how to get slope between two points, the y intercept of a line, and a2 + b2 = c2, I just can't recall / figure out how to use slope or angle to get a and b (x and y) given c.

visualization

Does anyone know a mathematical formula to figure out a and b given c, y-intercept and slope (or angle)? (AS3 is also fine.)

like image 957
Martin Avatar asked Jan 18 '26 04:01

Martin


2 Answers

You have a triangle:

  |\             a^2 + b^2 = c^2 = 16^2 = 256
  |  \                     
  |    \  c      a = sqrt(256 - b^2)
a |      \       b = sqrt(256 - a^2)
  |        \
  |__________\
       b

You also know (m is slope):

a/b = m
  a = m*b

From your original triangle:

      m*b = a = sqrt(256 - b^2)
m^2 * b^2 = 256 - b^2

Also, since m = c, you can say:

      m^2 * b^2 = m^2 - b^2
(m^2 + 1) * b^2 = m^2

Therefore:

b = m / sqrt(m^2 + 1)

I'm lazy so you can find a yourself: a = sqrt(m^2 - b^2)

like image 181
Blender Avatar answered Jan 19 '26 20:01

Blender


Let s be the slop.

we have: 1) s^2 = a^2/b^2 ==> a^2 = s^2 * b^2

and: 2) a^2 + b^2 = c^2 = 16*16

substitute a^2 in 2) with 1):

b = 16/sqrt(s^2+1)

and

a = sqrt((s^2 * 256)/(s^2 + 1)) = 16*abs(s)/sqrt(s^2+1)

In above, I assume you want to get the length of a and b. In reality, your s is a signed value, so a could be negative. Therefore, the incremental value of a will really be:

a = 16s/sqrt(s^2+1)
like image 40
Jingshao Chen Avatar answered Jan 19 '26 18:01

Jingshao Chen