point_handedness: Determine which side one point is to another, given a slope...

point_handednessR Documentation

Determine which side one point is to another, given a slope or angle

Description

Determine which side one point is to another, given a slope or angle

Usage

point_handedness(
  pt1,
  pt2,
  slope = NULL,
  angle = NULL,
  do_plot = FALSE,
  verbose = FALSE,
  ...
)

Arguments

pt1

numeric matrix of 2 columns, with x and y coordinates.

pt2

numeric matrix of 2 columns, with x and y coordinates.

slope

numeric slope for each point in pt1 and pt2.

do_plot

logical indicating whether to plot the result.

...

additional arguments are ignored.

Details

The result describes the position of the first line relative to the second line, assuming both lines are parallel with identical slope. For example "left" indicates that line 1 is on the left side of line 2. Note that the angle is a more accurate measure of directionality, otherwise slope is always assumed to desribe an angle moving to the right.

When both lines are exactly overlapping, the result may be unstable, however the result tends to favor "right" by default.

Value

character vector equal to the number of points, nrow(pt1):

  • "right" indicates pt1 is on the right side of pt2

  • "left" indicates pt1 is on the left side of pt2

See Also

Other jamses utilities: choose_annotation_colnames(), contrast2comp_dev(), fold_to_log2fold(), intercalate(), list2im_opt(), log2fold_to_fold(), make_block_arrow_polygon(), mark_stat_hits(), matrix_normalize(), point_slope_intercept(), shortest_unique_abbreviation(), shrinkDataFrame(), shrink_df(), shrink_matrix(), sort_samples(), strsplitOrdered(), sub_split_vector(), update_function_params(), update_list_elements()

Examples

pt1 <- matrix(ncol=2, c(1, 1))
pt2 <- matrix(ncol=2, c(2, 2))
point_handedness(pt1, pt2, angle=0, do_plot=TRUE)
point_handedness(pt1=c(1, 1), pt2=c(2, 2), angle=0, do_plot=TRUE)

pt1 <- matrix(ncol=2, c(1, 1))
pt2 <- matrix(ncol=2, c(0, 1))

point_handedness(pt1, pt2, angle=45, do_plot=TRUE)
point_handedness(pt2, pt1, angle=45, do_plot=TRUE)

point_handedness(rbind(pt2, pt2-1), rbind(pt1, pt1-1),
   angle=c(45, 45+180), do_plot=TRUE)

point_handedness(pt1, pt2, angle=45, do_plot=TRUE)
title(main="angle = 45,\n(slope = 1)")
point_handedness(pt1, pt2, angle=45 + 180, do_plot=TRUE)
title(main="angle = 225,\n(slope = 1)")

point_handedness(pt1, pt2, slope=Inf, do_plot=TRUE)
title(main="slope = Inf")
point_handedness(pt1, pt2, angle=90, do_plot=TRUE)
title(main="angle = 90")
point_handedness(pt2, pt1, slope=-Inf, do_plot=TRUE)
title(main="slope = -Inf")
point_handedness(pt2, pt1, angle = 270, do_plot=TRUE)
title(main="angle = 270")

point_handedness(pt1, pt2, slope=0, do_plot=TRUE)
point_handedness(pt2, pt1, slope=0, do_plot=TRUE)

pt1 <- matrix(ncol=2, c(-2, 5))
pt2 <- matrix(ncol=2, c(2, 3))
point_handedness(pt1, pt2, slope=1, do_plot=TRUE)
point_handedness(pt1, pt2, slope=-1, do_plot=TRUE)
point_handedness(pt1, pt2, slope=-1/3, do_plot=TRUE)
point_handedness(pt1, pt2, slope=-1/3, do_plot=TRUE)

point_handedness(pt1, pt2, slope=Inf, do_plot=TRUE)
point_handedness(pt1, pt2, slope=-Inf, do_plot=TRUE)


jmw86069/jamses documentation built on Nov. 4, 2024, 9:25 p.m.