Distance along the perpendicular line
Ältere Kommentare anzeigen
I have two line segments seg1 and seg2. The starting and ending points of each line segment is known. For example seg1=(x1,y1),(x2,y2) and seg2=(x3,y3),(x4,y4). I want to draw a perpendicular line through the mid point of seg1 (let's assume the mid point is (x0,y0)). Then I want to check whether this perpendicular line touches(crosses) seg2. If it crosses, then I want to calculate the distance along the perpendicular line to this crossing point(not the perpendicular distance from (x0,y0) to the crossing point/seg2)
Furthermore, I want to find the sign (+ or -) of the distance. i.e: If the seg2 is on the right side, the sign should be positive(+) and if it is on left, the sign should be negative (-).
Please help.
5 Kommentare
Jan
am 27 Sep. 2011
How do you define "right side" in 2D? By looking from (x1,y1) to (x2,y2) or the other way around?
Please post, what you have done already and where which problems occurred. Specific questions are replied more likely compared to a general description of a problem. If I post a working program now, it is not clear if it matchs your needs exactly and therefore this would be waste of time.
Ivan van der Kroon
am 27 Sep. 2011
maybe you can start with a perpendicular line having a slope that is equal to the negative reciprocal of the original line. So, slope1=(y2-y1)/(x2-x1) and the line y=y0+(x-x0)*-1/slope1 will go through (x0,y0) perpendicularly. I'm sure you can find a way to check whether it crosses line2. Be careful with y2-y1=0 or x2-x1=0 though. Good luck.
Devinya Herath
am 27 Sep. 2011
Jan
am 27 Sep. 2011
@Devinya: The problem is clear. What have you done so far?
Devinya Herath
am 27 Sep. 2011
Antworten (0)
Kategorien
Mehr zu Numeric Solvers finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!