Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

I am a programmer, but not much of a mathematician. How do I write the following formula?

I have a line segment. I know point A and B on a linear plane. I need to get point perpendicular to points A and B at some specified distance. I have include a simple sketch.I want to solve for points C, D, E, and F.

Update:

My goal is to get the dimensions of a polygon that will encompass the line segment.

Update 2:

If someone can solve with a snippet of a code in any programming language, I'll definitely award best answer. This one eludes me.

Attachment image

4 Answers

Relevance
  • 6 years ago
    Favorite Answer

    Suppose point A has coordinates (ax, ay), and point B has coordinates (bx, by). Then all points on line CD will match

    .. CD = (s*(by-ay)+ax, s*(ax-bx)+ay)

    for some scalar value of "s". Positive values of "s" will define points in the direction of C, and negative values will define points in the direction of D.

    We can similarly define points on line EF.

    .. EF = (t*(by-ay)+bx, t*(ax-bx)+by) ... positive "t" goes in the direction of E, negative "t" in the direction of F

    When s and t take on the values ±1/2, you will define four points C,D,E,F that are the corners of a square with AB joining midpoints of opposite sides. Of course there is no requirement that these have any value in particular. The larger they are, the bigger your polygon will be.

  • ?
    Lv 7
    6 years ago

    I think Postscript would be perfect for this. You have really done the math when you made the sketch.

    http://paulbourke.net/dataformats/postscript/

    Units are 1/72 inch. Here's the sample code to draw two connected line segments.

    newpath

    100 200 moveto

    200 250 lineto

    100 300 lineto

    2 setlinewidth

    stroke

    Stroke means to draw the line with line width of 2. Fill would fill the rectangle.

    If you know the coordinates of A (a1, A2) and D (D1, D2) , and the difference in the x coordinate of the endpoints of line AB is u and the difference in the y coordinates is v. Let A be at 0,0. and the coordinates of E and F are easy to compute. E = u,v, F = D1+u, D2+v,

    Postscript would define the lines directly:

    newpath

    0,0 lineto

    u,v lineto

    D1+u, D2+v

    lineto D1,D2

    lineto 0,0

    stroke

    Rem: or fill.

    I don't have a Postscript interpreter to test this, so you may have to change something. This code could print a rectangle directly on any postscript enabled device.

    Good luck!

  • ?
    Lv 7
    6 years ago

    Let A be (x1,y1) B be (x2,y2).

    The slope of the line between them is m=(y2-y1)/(x2-x1). The line perpendicular to AB at A has slope n=-1/m. The point slope equation of that line is (y-y1)/(x-x1)=n [1]. The equation of a circle with center at A and radius R has equation (x-x1)^2+(y-y1)^2=R^2 [2]. Find where eq 1 and eq 2 intersect. Substitute eq 1 into eq 2 and solve for x and y.

  • ?
    Lv 7
    6 years ago

    Use the dot-product relationships.

    https://en.wikipedia.org/wiki/Dot_product

    Define two vectors (using your picture) as follows:

    X = vector connecting points A & B

    Y = vector connecting points A & D

    ||X|| = distance between A & B

    ||Y|| = distance between A & F

    Want point F such that X*Y = ||X||*||Y||*cos (angle) = 0. This occurs only when angle = pi / 2 relative to the line segment (A, B)

Still have questions? Get your answers by asking now.