Given line1, line2, and distance d, I want to write a program to calculate the point on Line2 that is perpendicular to Line1, and the perpendicular distance is d.
Does anyone know where to start? In C or any other programming language.
Thanks in advance.
CodePudding user response:
@463035818_is_not_a_number is right, you need to do the math first. I would suggest to find the intersection point and the angle first: https://www.cuemath.com/geometry/intersection-of-two-lines/ Then you can calculate 'c' and then you can write sin(alpha)=d/c equation with (x,y). So you'll have line2 and the equation that you get in terms of x and y which gives you 2 equations with 2 unknowns. hope this helps.
CodePudding user response:
Given a line equation for line1 with y1 = m1 * x1 b1
we move this line in normal direction with the given distance d and have then y1 = m1 * x1 (b1 /- d)
. As you can see we could have 2 possible solutions if the lines are not parallel.
Now with the new line we search the intersection with line2, which is given by the formula:
Line Equations:
Line_1_with_d => y1 = m1 * x1 (b1 /- d)
Line_2 => y2 = m2 * x2 b2
Intersection Equations:
Point_x = (b2 - (b1 /- d)) / (m1 - m2)
(you will get here a problem if they are parallel)
Point_y = (m1 * (b2 - (b1 /- d))) / ((m1 - m2) (b1 /- d))
If the lines are parallel (which you should check first) you can test if the given distance d matches the distance of the lines:
d = (|b2 - b1|) / (sqrt(m^2 1))
(m1 == m2
if parallel)