Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find two points on a line parallel to another line

In the attached image.

enter image description here

How can we find the position values of point Q1 and Q2.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

this is my code but i am not able to get the points correctly.

How can we find the position values of point Q1 and Q2.

dim u as vertex
u = CVertex(P3.x - P4.x , P3.y - P4.y , 0.0)

dim v as vertex
v = CVertex( -u.y , u.x , v.z)

dim t1 as vertex
t1 = CVertex( (P1.x - P2.x) * v.x , (P1.y - P2.y) * v.y , 0.0)

dim t2 as vertex
t2 = CVertex( (P1.x - P3.x) * v.x , (P1.y - P3.y) * v.y , 0.0)

dim t as vertex 
 
t = CVertex( t1.x / t2.x ,  t1.y / t2.y  , 0.0)

dim Q1 as vertex

Q1.x  = P1.x +  t.x * (P3.x -  P1.x)
Q1.y  = P1.y +  t.y * (P3.y -  P1.y)

>Solution :

We make some vectors – for example, P31 = P3 - P1 and so on.
Points Q1, Q2 might be expressed as

Q1 = P1 + t * P31
Q2 = P1 + t * P41

where t is parameter in range 0..1 (for t=1 Q1 coincides with P3, Q2 coincides with P4).

Vectors q2-q1 and p2-q1 must be parallel, because Q1Q2 segment contains P2. So vector product of these vectors is zero. We express vector product using given vector components and solve simple linear equation to get t parameter that provides needed conditions.

Python code:

def segintri(p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y):
    p21x = p2x - p1x
    p21y = p2y - p1y
    p31x = p3x - p1x
    p31y = p3y - p1y
    p41x = p4x - p1x
    p41y = p4y - p1y
    p43x = p4x - p3x
    p43y = p4y - p3y
    t = (p43x * p21y - p43y*p21x) / (p43x * p31y - p43y*p31x)
    q1 = (p1x + p31x*t, p1y + p31y*t)
    q2 = (p1x + p41x*t, p1y + p41y*t)
    return (q1, q2)

print(segintri(1, 5, 2, 2, 0, 0, 6, 0))

>>>((0.4, 2.0), (4.0, 2.0))

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading