R/compute_PerpendicularSlopeAndIntercept_givenTwoPoints.R

Defines functions compute_PerpendicularSlopeAndIntercept_givenTwoPoints

Documented in compute_PerpendicularSlopeAndIntercept_givenTwoPoints

#' Compute perpendicular bisector coefficients given two points
#' 
#' @param point1_coord A vector of point 1 coordinate, where point1_coord[1] is the X-axis coordinate while point1_coord[2] is the Y-axis coordinate.
#' @param point2_coord A vector of point 2 coordinate, where point1_coord[1] is the X-axis coordinate while point1_coord[2] is the Y-axis coordinate.
#' @author Alexander Kheirallah ([email protected]).
#' @export

compute_PerpendicularSlopeAndIntercept_givenTwoPoints <- function(point1_coord=c(0,0),point2_coord=c(1,1)){
  ### Summary:
  ###   Computes the slope and intercept of line perpendicular to a line passing through two points such that it is equally distant between these two points (i.e. perpendicular bisector)
  
  ## 1) compute the slope and intercept of line1
  line1 <- compute_SlopeAndIntercept_givenTwoPoints(point1_coord = point1_coord, point2_coord = point2_coord)
  
  ## 2) compute the coordinates of midpoint between point1 and point2 present on the line passing through the points
  mid <- compute_midpoint_between_twoPoints_onLinePassingThroughThem(point1_coord=point1_coord, point2_coord=point2_coord)
  
  ## 3) compute the slope and intercept of line perpendicular to line1
  m <- (-1)/line1[1] # the slope of line1 // it's a negative reciprocal
  int <- mid[2] - m * mid[1]
  o <- c(m,int)
  names(o) <- c("slope", "intercept")
  return(o)
}
msxakk89/dat documentation built on March 25, 2020, 3:18 p.m.