Line: R6 class representing a line

LineR Documentation

R6 class representing a line

Description

A line is given by two distinct points, named A and B, and two logical values extendA and extendB, indicating whether the line must be extended beyond A and B respectively. Depending on extendA and extendB, the line is an infinite line, a half-line, or a segment.

Active bindings

A

get or set the point A

B

get or set the point B

extendA

get or set extendA

extendB

get or set extendB

Methods

Public methods


Method new()

Create a new Line object.

Usage
Line$new(A, B, extendA = TRUE, extendB = TRUE)
Arguments
A, B

points

extendA, extendB

logical values

Returns

A new Line object.

Examples
l <- Line$new(c(1,1), c(1.5,1.5), FALSE, TRUE)
l
l$A
l$A <- c(0,0)
l

Method print()

Show instance of a line object.

Usage
Line$print(...)
Arguments
...

ignored

Examples
Line$new(c(0,0), c(1,0), FALSE, TRUE)

Method length()

Segment length, returns the length of the segment joining the two points defining the line.

Usage
Line$length()

Method directionAndOffset()

Direction (angle between 0 and 2pi) and offset (positive number) of the reference line.

Usage
Line$directionAndOffset()
Details

The equation of the line is cos(θ)x+sin(θ)y=d where θ is the direction and d is the offset.


Method isEqual()

Check whether the reference line equals a given line, without taking into account extendA and extendB.

Usage
Line$isEqual(line)
Arguments
line

a Line object

Returns

TRUE or FALSE.


Method isParallel()

Check whether the reference line is parallel to a given line.

Usage
Line$isParallel(line)
Arguments
line

a Line object

Returns

TRUE or FALSE.


Method isPerpendicular()

Check whether the reference line is perpendicular to a given line.

Usage
Line$isPerpendicular(line)
Arguments
line

a Line object

Returns

TRUE or FALSE.


Method includes()

Whether a point belongs to the reference line.

Usage
Line$includes(M, strict = FALSE, checkCollinear = TRUE)
Arguments
M

the point for which we want to test whether it belongs to the line

strict

logical, whether to take into account extendA and extendB

checkCollinear

logical, whether to check the collinearity of A, B, M; set to FALSE only if you are sure that M is on the line (AB) in case if you use strict=TRUE

Returns

TRUE or FALSE.

Examples
A <- c(0,0); B <- c(1,2); M <- c(3,6)
l <- Line$new(A, B, FALSE, FALSE)
l$includes(M, strict = TRUE)

Method perpendicular()

Perpendicular line passing through a given point.

Usage
Line$perpendicular(M, extendH = FALSE, extendM = TRUE)
Arguments
M

the point through which the perpendicular passes.

extendH

logical, whether to extend the perpendicular line beyond the meeting point

extendM

logical, whether to extend the perpendicular line beyond the point M

Returns

A Line object; its two points are the meeting point and the point M.


Method parallel()

Parallel to the reference line passing through a given point.

Usage
Line$parallel(M)
Arguments
M

a point

Returns

A Line object.


Method projection()

Orthogonal projection of a point to the reference line.

Usage
Line$projection(M)
Arguments
M

a point

Returns

A point.


Method distance()

Distance from a point to the reference line.

Usage
Line$distance(M)
Arguments
M

a point

Returns

A positive number.


Method reflection()

Reflection of a point with respect to the reference line.

Usage
Line$reflection(M)
Arguments
M

a point

Returns

A point.


Method rotate()

Rotate the reference line.

Usage
Line$rotate(alpha, O, degrees = TRUE)
Arguments
alpha

angle of rotation

O

center of rotation

degrees

logical, whether alpha is given in degrees

Returns

A Line object.


Method translate()

Translate the reference line.

Usage
Line$translate(v)
Arguments
v

the vector of translation

Returns

A Line object.


Method invert()

Invert the reference line.

Usage
Line$invert(inversion)
Arguments
inversion

an Inversion object

Returns

A Circle object or a Line object.


Method clone()

The objects of this class are cloneable with this method.

Usage
Line$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `Line$new`
## ------------------------------------------------

l <- Line$new(c(1,1), c(1.5,1.5), FALSE, TRUE)
l
l$A
l$A <- c(0,0)
l

## ------------------------------------------------
## Method `Line$print`
## ------------------------------------------------

Line$new(c(0,0), c(1,0), FALSE, TRUE)

## ------------------------------------------------
## Method `Line$includes`
## ------------------------------------------------

A <- c(0,0); B <- c(1,2); M <- c(3,6)
l <- Line$new(A, B, FALSE, FALSE)
l$includes(M, strict = TRUE)

PlaneGeometry documentation built on Aug. 10, 2023, 1:09 a.m.