I want to use MetaPost to draw a right angle BAC. A = (20,30), B = (0,0), the top of the angle is point A.

How can I compute the coordinate of point C?

The Right Angle

  • Angle's top is on which point?
    – Thanos
    Commented Nov 3, 2012 at 12:21
  • It is point A. Commented Nov 3, 2012 at 12:22
  • since the right angle B is at origin, you can have C at (-20,30) or (20,-30) based on A's coordinate.
    – mythealias
    Commented Nov 3, 2012 at 12:36
  • Oops, I made a terrible typo. In fact, I want to draw right angle BAC. Commented Nov 3, 2012 at 12:41

4 Answers 4


You can use dotprod:

(z1-z0) dotprod (z2-z1)=0;
draw z0--z1--z2--cycle;

run with xelatex

       A.y B.y sub A.x add A.x B.x sub neg A.y add ){C}{C}
  B.y A.y sub B.x A.x sub atan}{!B.y A.y sub B.x A.x sub atan 90 add}%

enter image description here

  • I use MetaPost only. Commented Nov 3, 2012 at 13:10
  • should not be difficult to write \drawAngle in Metapost. You can use B.x also in MP.
    – user2478
    Commented Nov 3, 2012 at 13:19

Just 4 fun with PSTricks:

enter image description here



  • \psset{PointSymbol=none} to turn the dots off.

  • \pstGeonode[PosAngle={45,-135}](2,3){A}(0,0){B} to specify the point A and B.

  • \pstRotation[RotAngle=90,PointName=none]{A}{B} to rotate point B 90 degrees about A, the new point is implicitly named as B'.

  • \pnode(A|B){B''} to define an auxiliary point B'' whose coordinate is (A.x,B.y).

  • \pstInterLL{A}{B'}{B}{B''}{C} to find the intersection point C between the lines AB' and BB''.

  • \pspolygon(A)(B)(C) to draw the triangle ABC.

  • \pstRightAngle{B}{A}{C} to attach the L-shape right angle mark.

  • 1
    I'm using MetaPost, but it's really a good tutorial! Commented Nov 9, 2012 at 8:41

First of all you understand that there are infinite point that are perpindicular to AB. So actually you are looking for a line. To find it, just assume the vector AB with coordinates BA=(20-0,30-0)=(20,30)=a and vector BC=(x-0, y-0)=(x,y)=b.

To find vector coordinates you just apply (xend-xstart, yend-ystart). The requirement you have is that a and b must be perpendicular. In vector analysis, this means that the dot product must be zero, ie


So choose an x apply the previous line equation and you'll get your y.

Edit: I saw you changed your question. In that way you will have a new line with same slope but with different intercept. So your line will be something like


with u being the same slope, u=-2/3, that is. On the same time it should pass from point A so this point has to be a solution of the line. So replacing A's coordinates in line equation you'll get


So your new line is


Again for every x you'll get a y.

  • Can I write a MetaPost macro to solve it? Commented Nov 3, 2012 at 13:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .