# Draw a perpendicular line?

6 messages
Open this post in threaded view
|

## Draw a perpendicular line?

 Hi, I am trying to draw a perpendicular line from a point to two points. Mathematically I know how to do it, but to program it, I encounter some problem and hope can get help.  Thanks. I have points, A, B and C.  I calculate the slope and intercept for line drawn between A and B. I am trying to check whether I can draw a perpendicular line from C to line AB and get the x,y value for the point D at the intersection. Assume I get the slope of the perpendicular line, I will have my point (D) using variable x and y which is potentially on line AB.   My idea was using |AC|*|AC| = |AD|*|AD|+ |CD|*|CD|.  I don't know what function I may need to call to calculate the values for point D (uniroot?). Thank you.
Open this post in threaded view
|

## Re: Draw a perpendicular line?

 Maybe perp.slope = -1/slope abline(cy - cx*perp.slope, perp.slope) where cx, cy are x- and y-coordinate of C, resp., and slope the slope you calculated for the line through A and B Am 24.Aug.2010 um 0:04 schrieb CZ: > > Hi, > > I am trying to draw a perpendicular line from a point to two points. > Mathematically I know how to do it, but to program it, I encounter some > problem and hope can get help.  Thanks. > > I have points, A, B and C.  I calculate the slope and intercept for line > drawn between A and B. > I am trying to check whether I can draw a perpendicular line from C to line > AB and get the x,y value for the point D at the intersection. > > Assume I get the slope of the perpendicular line, I will have my point (D) > using variable x and y which is potentially on line AB.   My idea was using > |AC|*|AC| = |AD|*|AD|+ |CD|*|CD|.  I don't know what function I may need to > call to calculate the values for point D (uniroot?). > > Thank you. > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Draw-a-perpendicular-line-tp2335882p2335882.html> Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Draw a perpendicular line?

 hi, also, make sure you have set the aspect ratio to 1:1 when plotting (asp=1). HTH, baptiste On 25 August 2010 10:20, Benno Pütz <[hidden email]> wrote: > Maybe > > perp.slope = -1/slope > abline(cy - cx*perp.slope, perp.slope) > > where cx, cy are x- and y-coordinate of C, resp., and slope the slope you calculated for the line through A and B > > > Am 24.Aug.2010 um 0:04 schrieb CZ: > >> >> Hi, >> >> I am trying to draw a perpendicular line from a point to two points. >> Mathematically I know how to do it, but to program it, I encounter some >> problem and hope can get help.  Thanks. >> >> I have points, A, B and C.  I calculate the slope and intercept for line >> drawn between A and B. >> I am trying to check whether I can draw a perpendicular line from C to line >> AB and get the x,y value for the point D at the intersection. >> >> Assume I get the slope of the perpendicular line, I will have my point (D) >> using variable x and y which is potentially on line AB.   My idea was using >> |AC|*|AC| = |AD|*|AD|+ |CD|*|CD|.  I don't know what function I may need to >> call to calculate the values for point D (uniroot?). >> >> Thank you. >> >> >> >> -- >> View this message in context: http://r.789695.n4.nabble.com/Draw-a-perpendicular-line-tp2335882p2335882.html>> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> [hidden email] mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html>> and provide commented, minimal, self-contained, reproducible code. >> > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. > -- ____________________ Dr. Baptiste Auguié Departamento de Química Física, Universidade de Vigo, Campus Universitario, 36310, Vigo, Spain tel: +34 9868 18617 http://webs.uvigo.es/coloides______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Draw a perpendicular line?

 In reply to this post by CZ At 3:04 PM -0700 8/23/10, CZ wrote: >Hi, > >I am trying to draw a perpendicular line from a point to two points. >Mathematically I know how to do it, but to program it, I encounter some >problem and hope can get help.  Thanks. > >I have points, A, B and C.  I calculate the slope and intercept for line >drawn between A and B. >I am trying to check whether I can draw a perpendicular line from C to line >AB and get the x,y value for the point D at the intersection. > >Assume I get the slope of the perpendicular line, I will have my point (D) >using variable x and y which is potentially on line AB.   My idea was using >|AC|*|AC| = |AD|*|AD|+ |CD|*|CD|.  I don't know what function I may need to >call to calculate the values for point D (uniroot?). This is easier than you think. Think of the x,y coordinates of each point : Then, the slope is slope = rise/run =  (By- Ay)/(Bx- Ax) The Dx coordinate = Cx and the Dy = (Dx - Ax) * slope Then, to draw the line segment from C to D lines(C,D) In R: A <- c(2,4) B <- c(4,1) C <- c(8,10) slope <-( C[2]- A[2])/(C[1]-A[1])  #rise/run D <- c(B[1],(B[1]-A[1])*slope + A[2])  # find D my.data <- rbind(A,B,C,D) colnames(my.data) <- c("X","Y") my.data    #show it plot(my.data,type="n")   #graph it without the points text(my.data,rownames(my.data))  #put the points in segments(A[1],A[2],C[1],C[2])   #draw the line segments segments(B[1],B[2],D[1],D[2]) Bill > >Thank you. > > > >-- >View this message in context: >http://r.789695.n4.nabble.com/Draw-a-perpendicular-line-tp2335882p2335882.html>Sent from the R help mailing list archive at Nabble.com. > >______________________________________________ >[hidden email] mailing list >https://stat.ethz.ch/mailman/listinfo/r-help>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html>and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.