Title: | Learning Plane Geometry |
---|---|
Description: | Contains some functions to learn and teach basic plane Geometry at undergraduate level with the aim of being helpful to young students with little programming skills. |
Authors: | Alvaro Briz-Redon, Angel Serrano-Aroca |
Maintainer: | Alvaro Briz-Redon <[email protected]> |
License: | GPL-2 |
Version: | 1.5 |
Built: | 2025-03-01 04:51:19 UTC |
Source: | https://github.com/cran/LearnGeom |
AddPointPoly
creates a matrix to represent the polygon that connects several points
AddPointPoly(Poly, point, position)
AddPointPoly(Poly, point, position)
Poly |
Polygon object, previously created with function |
point |
Vector containing the xy-coordinates of the point to be added to the polygon |
position |
Integer indicating the position of the point in the original polygon, after which the new point is being added (considering that every polygon is an ordered list of points). It is convenient to visualize the polygon with |
Returns a matrix which contains the points of the polygon. Each row represents one of the points
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) n <- 5 C <- c(0,0) l <- 2 Penta <- CreateRegularPolygon(n, C, l) Penta <- AddPointPoly(Penta, CenterPolygon(Penta), 1) Draw(Penta, "blue", label = TRUE)
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) n <- 5 C <- c(0,0) l <- 2 Penta <- CreateRegularPolygon(n, C, l) Penta <- AddPointPoly(Penta, CenterPolygon(Penta), 1) Draw(Penta, "blue", label = TRUE)
Angle
computes the angle between three points
Angle(A, B, C, label = FALSE)
Angle(A, B, C, label = FALSE)
A |
Vector containing the xy-cooydinates of point A |
B |
Vector containing the xy-cooydinates of point B. This point acts as the vertex of angle ABC |
C |
Vector containing the xy-cooydinates of point C |
label |
Boolean. When |
Angle between the three points in degrees
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) A <- c(-1,0) B <- c(0,0) C <- c(0,1) Draw(CreatePolygon(A, B, C), "transparent") angle <- Angle(A, B, C, label = TRUE) angle <- Angle(A, C, B, label = TRUE) angle <- Angle(B, A, C, label = TRUE)
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) A <- c(-1,0) B <- c(0,0) C <- c(0,1) Draw(CreatePolygon(A, B, C), "transparent") angle <- Angle(A, B, C, label = TRUE) angle <- Angle(A, C, B, label = TRUE) angle <- Angle(B, A, C, label = TRUE)
CenterPolygon
computes the center of a polygon
CenterPolygon(Poly)
CenterPolygon(Poly)
Poly |
Polygon object, previously created with either of the functions |
Vector which contains the xy-coordinates of the center of the polygon
P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) C <- CenterPolygon(Poly) x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) Draw(Poly, "blue") Draw(C, "red")
P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) C <- CenterPolygon(Poly) x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) Draw(Poly, "blue") Draw(C, "red")
Circumcenter
computes the center of a triangle
Circumcenter(Tri, lines = F)
Circumcenter(Tri, lines = F)
Tri |
Triangle object, previously created with function |
lines |
Boolean. When |
Vector which contains the xy-coordinates of the circumcenter of the triangle
http://mathworld.wolfram.com/Circumcenter.html
P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Tri <- CreatePolygon(P1, P2, P3) x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) Draw(Tri, "transparent") I <- Circumcenter(Tri, lines = TRUE) Draw(I, "red")
P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Tri <- CreatePolygon(P1, P2, P3) x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) Draw(Tri, "transparent") I <- Circumcenter(Tri, lines = TRUE) Draw(I, "red")
CoordinatePlane
plots an empty coordinate (cartesian) plane with customizable limits for the X and Y axis.
CoordinatePlane(x_min, x_max, y_min, y_max)
CoordinatePlane(x_min, x_max, y_min, y_max)
x_min |
Lowest value for the X axis |
x_max |
Highest value for the X axis |
y_min |
Lowest value for the Y axis |
y_max |
Highest value for the Y axis |
None. It produces a plot of a coordinate plane with axes and grid
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max)
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max)
CreateArcAngles
creates an arc of a circumference
CreateArcAngles(C, r, angle1, angle2, direction = "anticlock")
CreateArcAngles(C, r, angle1, angle2, direction = "anticlock")
C |
Vector containing the xy-coordinates of the center of the circumference |
r |
Radius for the circumference (or arc) |
angle1 |
- Angle in degrees (0-360) at which the arc starts |
angle2 |
- Angle in degrees (0-360) at which the arc finishes |
direction |
- String indicating the direction which is considered to create the arc, from the smaller to the higher angle. It has two possible values: "clock" (clockwise direction) and "anticlock" (anti-clockwise direction) |
Returns a vector which contains the center, radius, angles (0-360) and direction (1 - "clock", 2 - "anticlock") that define the created arc
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) C <- c(0,0) r <- 3 angle1 <- 90 angle2 <- 180 direction <- "anticlock" Arc1 <- CreateArcAngles(C, r, angle1, angle2, direction) Draw(Arc1, "black") direction <- "clock" Arc2 <- CreateArcAngles(C, r, angle1, angle2, direction) Draw(Arc2, "red")
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) C <- c(0,0) r <- 3 angle1 <- 90 angle2 <- 180 direction <- "anticlock" Arc1 <- CreateArcAngles(C, r, angle1, angle2, direction) Draw(Arc1, "black") direction <- "clock" Arc2 <- CreateArcAngles(C, r, angle1, angle2, direction) Draw(Arc2, "red")
CreateArcPointsDist
creates an arc of a circumference to connect two points
CreateArcPointsDist(P1, P2, r, choice, direction)
CreateArcPointsDist(P1, P2, r, choice, direction)
P1 |
Vector containing the xy-coordinates of point 1 |
P2 |
Vector containing the xy-coordinates of point 2 |
r |
Radius for the circumference which is used to generate the arc. This parameter is necessary because there are infinite possible arcs that connect two points. In the case the radius is smaller than half the distance between |
choice |
- Integer indicating which of the two possible centers is chosen to create the arcs. A value of 1 means the center of the circle that contains the arc is chosen in the direction of M + v, being M the middle point between P1 and P2 and v the orthogonal vector of P2 - P1 normalized to the appropriate length for creating the desired arc. A value of 2 means the center of the resulting circle is chosen in the direction of M - V. Remark: There are as well two options for vector v. If P1 = (a,b) and P2 = (c,d), v is written in the internal function as (b-d,c-a) |
direction |
- String indicating the direction which is considered to create the arc, from the smaller to the higher angle. It has two possible values: "clock" (clockwise direction) and "anticlock" (anti-clockwise direction) |
Returns a vector which contains the center, radius and angles (0-360) that define the created arc
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(-3,2) P2 <- c(0,0) r <- sqrt(18)/2 choice=1 direction="anticlock" Arc <- CreateArcPointsDist(P1, P2, r, choice, direction) Draw(Arc, "red") choice=2 direction="anticlock" Arc <- CreateArcPointsDist(P1, P2, r, choice, direction) Draw(Arc, "blue") choice=1 direction="clock" Arc <- CreateArcPointsDist(P1, P2, r, choice, direction) Draw(Arc, "pink") choice=2 direction="clock" Arc <- CreateArcPointsDist(P1, P2, r, choice, direction) Draw(Arc, "green")
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(-3,2) P2 <- c(0,0) r <- sqrt(18)/2 choice=1 direction="anticlock" Arc <- CreateArcPointsDist(P1, P2, r, choice, direction) Draw(Arc, "red") choice=2 direction="anticlock" Arc <- CreateArcPointsDist(P1, P2, r, choice, direction) Draw(Arc, "blue") choice=1 direction="clock" Arc <- CreateArcPointsDist(P1, P2, r, choice, direction) Draw(Arc, "pink") choice=2 direction="clock" Arc <- CreateArcPointsDist(P1, P2, r, choice, direction) Draw(Arc, "green")
CreateLineAngle
creates a vector to represent a line that passes through a point and forms certain angle with X axis
CreateLineAngle(P, angle)
CreateLineAngle(P, angle)
P |
Vector containing the xy-coordinates of a point |
angle |
Angle in degrees (0-360) for the line |
Returns a vector which contains the slope and intercept of the defined line. If the angle is defined as 90, the slope is set to Inf
and the intercept is replaced by the x-value for the line (which is a vertical line in this situation)
P <- c(0,0) angle <- 45 Line <- CreateLineAngle(P, angle)
P <- c(0,0) angle <- 45 Line <- CreateLineAngle(P, angle)
CreateLinePoints
creates a vector that represents the line that connects two points
CreateLinePoints(P1, P2)
CreateLinePoints(P1, P2)
P1 |
Vector containing the xy-coordinates of point 1 |
P2 |
Vector containing the xy-coordinates of point 2 |
Returns a vector which contains the slope and intercept of the defined line. If the points have the same x-coordinate, the slope is set to Inf
and the intercept is replaced by the x-value for the line (which is a vertical line in this situation)
P1 <- c(0,0) P2 <- c(1,1) Line <- CreateLinePoints(P1, P2)
P1 <- c(0,0) P2 <- c(1,1) Line <- CreateLinePoints(P1, P2)
CreatePolygon
creates a matrix to represent the polygon that connects several points
CreatePolygon(...)
CreatePolygon(...)
... |
An undetermined number of points introduced by the user in the form of vectors |
Returns a matrix which contains the points of the polygon. Each row represents one of the points
P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3)
P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3)
CreateRegularPolygon
creates a matrix to represent the polygon that connects several points
CreateRegularPolygon(n, C, l)
CreateRegularPolygon(n, C, l)
n |
Number of sides for the polygon |
C |
Vector containing the xy-coordinates for the center of the regular polygon |
l |
Length of the sides for the polygon |
Returns a matrix which contains the points of a regular polygon given its number of points and the length of its sides. Each row represents one of the points
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) n <- 5 C <- c(0,0) l <- 1 Penta <- CreateRegularPolygon(n, C, l) Draw(Penta, "blue", label = TRUE)
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) n <- 5 C <- c(0,0) l <- 1 Penta <- CreateRegularPolygon(n, C, l) Draw(Penta, "blue", label = TRUE)
DrawSegment
plots the segment that connects two points in a previously generated coordinate plane
CreateSegmentAngle(P, angle, l)
CreateSegmentAngle(P, angle, l)
P |
Vector containing the xy-coordinates of the point |
angle |
Angle in degrees (0-360) for the segment |
l |
Positive number that indicates the length for the segment |
Returns a matrix which contains the points that determine the extremes of the segment
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P <- c(0,0) angle <- 30 l <- 1 Segment <- CreateSegmentAngle(P, angle, l) Draw(Segment, "black")
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P <- c(0,0) angle <- 30 l <- 1 Segment <- CreateSegmentAngle(P, angle, l) Draw(Segment, "black")
DrawSegment
plots the segment that connects two points in a previously generated coordinate plane
CreateSegmentPoints(P1, P2)
CreateSegmentPoints(P1, P2)
P1 |
Vector containing the xy-coordinates of point 1 |
P2 |
Vector containing the xy-coordinates of point 2 |
Returns a matrix which contains the points that determine the extremes of the segment
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(0,0) P2 <- c(1,1) Segment <- CreateSegmentPoints(P1, P2) Draw(Segment, "black")
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(0,0) P2 <- c(1,1) Segment <- CreateSegmentPoints(P1, P2) Draw(Segment, "black")
DistanceLines
computes the distance between two lines
DistanceLines(Line1, Line2)
DistanceLines(Line1, Line2)
Line1 |
Line object previously created with |
Line2 |
Line object previously created with |
Returns the distance between two points
P1 <- c(0,0) P2 <- c(1,1) Line1 <- CreateLinePoints(P1, P2) P3 <- c(1,-1) P4 <- c(2,0) Line2 <- CreateLinePoints(P3, P4) d <- DistanceLines(Line1, Line2)
P1 <- c(0,0) P2 <- c(1,1) Line1 <- CreateLinePoints(P1, P2) P3 <- c(1,-1) P4 <- c(2,0) Line2 <- CreateLinePoints(P3, P4) d <- DistanceLines(Line1, Line2)
DistancePointLine
computes the distance between a point and a line
DistancePointLine(P, Line)
DistancePointLine(P, Line)
P |
Vector containing the xy-coordinates of a point |
Line |
Vector object previously created with |
Returns the distance between a point and a line. This distance corresponds to the distance between the point and its orthogonal projection into the line
P <- c(2,1) P1 <- c(0,0) P2 <- c(1,1) Line <- CreateLinePoints(P1, P2) d <- DistancePointLine(P, Line)
P <- c(2,1) P1 <- c(0,0) P2 <- c(1,1) Line <- CreateLinePoints(P1, P2) d <- DistancePointLine(P, Line)
DistancePoints
computes the distance between two points
DistancePoints(P1, P2)
DistancePoints(P1, P2)
P1 |
Vector containing the xy-coordinates of point 1 |
P2 |
Vector containing the xy-coordinates of point 2 |
Returns the euclidean distance between two points
P1 <- c(0,0) P2 <- c(1,1) d <- DistancePoints(P1, P2)
P1 <- c(0,0) P2 <- c(1,1) d <- DistancePoints(P1, P2)
Draw
plots geometric objects
Draw(object, colors = c("black", "black"), label = FALSE)
Draw(object, colors = c("black", "black"), label = FALSE)
object |
geometric object of any of these five types: point, segment, arc, line or polygon. A point is simply a vector of length 2, which contains the xy-coordinates for the point. For the other four types, there can be created with any of the following functions: |
colors |
Vector containing information about the color for the object to be plotted. In the case of polygons, the vector should have length 2 to define the background color and the border color (in this order). Moreover, it can be used |
label |
Boolean, only used for polygons. When |
None. It produces the plot of a geometric object (point, segment, arc, line or polygon) in the current coordinate plane
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) Draw(Poly, c("blue"))
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) Draw(Poly, c("blue"))
Duopoly
plots a closed curve from the trochoids family
Duopoly(P, l1, angle1, l2, angle2, time = 0, color = "transparent")
Duopoly(P, l1, angle1, l2, angle2, time = 0, color = "transparent")
P |
Vector containing the xy-coordinates of the starting point for the curve |
l1 |
Number that indicates the length side of the segment drawn the first in each of the steps of the process |
angle1 |
Angle (0-360) that indicates the direction of the segment which is drawn the first in each of the steps of the process |
l2 |
Number that indicates the length side of the segment drawn the second in each of the steps of the process |
angle2 |
Angle (0-360) that indicates the direction of the segment which is drawn the second in each of the steps of the process |
time |
Number of seconds to wait for the program before drawing each of the segments that make the trochoid curve. If no |
color |
Color to indicate the points that are obtained during the process to approximate the trochoid. If missing, the points are not indicated and only the segments are drawn in the plot |
None. It produces the plot of a curve from the trochoids family
Abelson, H., & DiSessa, A. A. (1986). Turtle geometry: The computer as a medium for exploring mathematics. MIT press
Armon, U. (1996). Representing trochoid curves by DUOPOLY procedure. International Journal of Mathematical Education in Science and Technology, 27(2), 177-187
x_min <- -100 x_max <- 100 y_min <- -50 y_max <- 150 CoordinatePlane(x_min, x_max, y_min, y_max) P <- c(0,0) l1 <- 2 angle1 <- 3 l2 <- 2 angle2 <- 10 Duopoly(P, l1, angle1, l2, angle2)
x_min <- -100 x_max <- 100 y_min <- -50 y_max <- 150 CoordinatePlane(x_min, x_max, y_min, y_max) P <- c(0,0) l1 <- 2 angle1 <- 3 l2 <- 2 angle2 <- 10 Duopoly(P, l1, angle1, l2, angle2)
FractalSegment
plots the first iterations of a fractal curve, starting from a segment in the plane
FractalSegment(P1, P2, angle, cut1, cut2, f, it)
FractalSegment(P1, P2, angle, cut1, cut2, f, it)
P1 |
Vector containing the xy-coordinates of point 1. This point is the left extreme of the segment that corresponds to the first iteration ( |
P2 |
Vector containing the xy-coordinates of point 2. This point is the right extreme of the segment that corresponds to the first iteration ( |
angle |
Angle (0-360) that determines the angle with which the new segments are drawn at the cut points |
cut1 |
Number bigger than 0 and smaller than 1 that indicates the proportional part of the segment at which the first cut occurs. This parameter determines the position of the first cut point |
cut2 |
Number bigger than 0 and smaller than 1 that indicates the proportional part of the segment at which the second cut occurs. This parameter determines the position of the second cut point |
f |
Positive number that produces an enlargement or a reduction for the new drawn segment in each iteration |
it |
Number of iterations to be performed for the construction of the fractal curve. It is not recommended to choose a number higher than 7 in order to avoid an excess of computation |
None. It produces the plot of the first n
iterations of a fractal curve in the current coordinate plane. The choice of parameters cut1 = 1/3
, cut2 = 2/3
, angle = 60
and f = 1
produces the Koch curve
http://mathworld.wolfram.com/Fractal.html
x_min <- -6 x_max <- 6 y_min <- -4 y_max <- 8 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(-5,0) P2 <- c(5,0) angle <- 90 cut1 <- 1/3 cut2 <- 2/3 f <- 1 it <- 4 FractalSegment(P1, P2, angle, cut1, cut2, f, it)
x_min <- -6 x_max <- 6 y_min <- -4 y_max <- 8 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(-5,0) P2 <- c(5,0) angle <- 90 cut1 <- 1/3 cut2 <- 2/3 f <- 1 it <- 4 FractalSegment(P1, P2, angle, cut1, cut2, f, it)
Homothety
creates an homothety from a given polygon
Homothety(Poly, C, k, lines = F)
Homothety(Poly, C, k, lines = F)
Poly |
Polygon object, previously created with function |
C |
Vector containing the xy-coordinates of the center of the homothety |
k |
Number which represents the expansion or contraction factor for the homothety |
lines |
Boolean. When |
Returns the coordinates of a polygon that has been transformed according to the homothethy with center at C
and factor k
https://www.encyclopediaofmath.org/index.php/Homothety
x_min <- -2 x_max <- 6 y_min <- -3 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) Draw(Poly, "blue") C <- c(-1,-2) k1 <- 0.5 Poly_homothety1 <- Homothety(Poly, C, k1, lines = TRUE) Draw(Poly_homothety1, "orange") k2 <- 2 Poly_homothety2 <- Homothety(Poly, C, k2, lines = TRUE) Draw(Poly_homothety2, "orange")
x_min <- -2 x_max <- 6 y_min <- -3 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) Draw(Poly, "blue") C <- c(-1,-2) k1 <- 0.5 Poly_homothety1 <- Homothety(Poly, C, k1, lines = TRUE) Draw(Poly_homothety1, "orange") k2 <- 2 Poly_homothety2 <- Homothety(Poly, C, k2, lines = TRUE) Draw(Poly_homothety2, "orange")
Incenter
computes the center of a triangle
Incenter(Tri, lines = F)
Incenter(Tri, lines = F)
Tri |
Triangle object, previously created with function |
lines |
Boolean. When |
Vector which contains the xy-coordinates of the incenter of the triangle
http://mathworld.wolfram.com/Incenter.html
P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Tri <- CreatePolygon(P1, P2, P3) x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) Draw(Tri, "transparent") I <- Incenter(Tri, lines = TRUE) Draw(I, "red")
P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Tri <- CreatePolygon(P1, P2, P3) x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) Draw(Tri, "transparent") I <- Incenter(Tri, lines = TRUE) Draw(I, "red")
IntersectLineCircle
finds the intesection between a line and a circumference
IntersectLineCircle(Line, C, r)
IntersectLineCircle(Line, C, r)
Line |
Line object previously created with |
C |
Vector containing the xy-coordinates of the center of the circumference |
r |
Radius for the circumference |
Returns a vector containing the xy-coordinates of the intersection points. In case of no intersection, the function tells the user
P1 <- c(0,0) P2 <- c(1,1) Line <- CreateLinePoints(P1, P2) C <- c(0,0) r <- 2 intersection <- IntersectLineCircle(Line, C, r) x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) Draw(Line, "black") Draw(CreateArcAngles(C, r, 0, 360), "black") Draw(intersection[1,], "red") Draw(intersection[2,], "red")
P1 <- c(0,0) P2 <- c(1,1) Line <- CreateLinePoints(P1, P2) C <- c(0,0) r <- 2 intersection <- IntersectLineCircle(Line, C, r) x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) Draw(Line, "black") Draw(CreateArcAngles(C, r, 0, 360), "black") Draw(intersection[1,], "red") Draw(intersection[2,], "red")
IntersectLines
finds the intesection of two lines
IntersectLines(Line1, Line2)
IntersectLines(Line1, Line2)
Line1 |
Line object previously created with |
Line2 |
Line object previously created with |
Returns a vector containing the xy-coordinates of the intersection point. In case of no intersection, the function tells the user
P1 <- c(0,0) P2 <- c(1,1) Line1 <- CreateLinePoints(P1, P2) P3 <- c(1,-1) P4 <- c(2,0) Line2 <- CreateLinePoints(P3, P4) intersection <- IntersectLines(Line1, Line2)
P1 <- c(0,0) P2 <- c(1,1) Line1 <- CreateLinePoints(P1, P2) P3 <- c(1,-1) P4 <- c(2,0) Line2 <- CreateLinePoints(P3, P4) intersection <- IntersectLines(Line1, Line2)
Koch
plots the first iterations of Koch curve, a well-known fractal
Koch(P1, P2, it)
Koch(P1, P2, it)
P1 |
Vector containing the xy-coordinates of point 1. This point is the left extreme of the segment that corresponds to the first iteration ( |
P2 |
Vector containing the xy-coordinates of point 2. This point is the right extreme of the segment that corresponds to the first iteration ( |
it |
Number of iterations to be performed for the construction of Koch curve. It is not recommended to choose a number higher than 7 in order to avoid an excess of computation |
None. It produces the plot of the first n
iterations of Koch curve in the current coordinate plane
http://mathworld.wolfram.com/KochSnowflake.html
x_min <- -6 x_max <- 6 y_min <- -4 y_max <- 8 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(-5,0) P2 <- c(5,0) it <- 4 Koch(P1, P2, it)
x_min <- -6 x_max <- 6 y_min <- -4 y_max <- 8 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(-5,0) P2 <- c(5,0) it <- 4 Koch(P1, P2, it)
LinesAngles
computes the angle that form two lines
LinesAngles(Line1, Line2)
LinesAngles(Line1, Line2)
Line1 |
Line object previously created with |
Line2 |
Line object previously created with |
Returns the angle that form the two lines
P1 <- c(0,0) P2 <- c(1,1) Line1 <- CreateLinePoints(P1, P2) P3 <- c(1,-1) P4 <- c(2,3) Line2 <- CreateLinePoints(P3, P4) angle <- LinesAngles(Line1, Line2)
P1 <- c(0,0) P2 <- c(1,1) Line1 <- CreateLinePoints(P1, P2) P3 <- c(1,-1) P4 <- c(2,3) Line2 <- CreateLinePoints(P3, P4) angle <- LinesAngles(Line1, Line2)
MidPoint
computes the middle point of the segment that connects two points
MidPoint(P1, P2)
MidPoint(P1, P2)
P1 |
Vector containing the xy-coordinates of point 1 |
P2 |
Vector containing the xy-coordinates of point 2 |
Returns a vector containing the xy-coordinates of the middle point of the segment that connects P1
and P2
P1 <- c(0,0) P2 <- c(1,1) mid <- MidPoint(P1, P2)
P1 <- c(0,0) P2 <- c(1,1) mid <- MidPoint(P1, P2)
PolygonAngles
computes each of the existing angles in a given polygon
PolygonAngles(Poly)
PolygonAngles(Poly)
Poly |
Polygon object, previously created with function |
Returns a vector containing the angles for each of the points of a polygon. The resulting vector follows the order of the points in the defined polygon
P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) angles <- PolygonAngles(Poly)
P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) angles <- PolygonAngles(Poly)
ProjectPoint
computes the orthogonal projection of a point onto a line
ProjectPoint(P, Line)
ProjectPoint(P, Line)
P |
Vector containing the xy-coordinates of a point |
Line |
Line object previously created with |
Returns a vector which contains the xy-coordinates of the projection point
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) xx <- c(0,1,2) yy <- c(0,1,0) P1 <- c(0,0) P2 <- c(1,1) Line <- CreateLinePoints(P1, P2) Draw(Line, "black") P <- c(-2,2) Draw(P, "black") projection <- ProjectPoint(P, Line) Draw(projection, "red")
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) xx <- c(0,1,2) yy <- c(0,1,0) P1 <- c(0,0) P2 <- c(1,1) Line <- CreateLinePoints(P1, P2) Draw(Line, "black") P <- c(-2,2) Draw(P, "black") projection <- ProjectPoint(P, Line) Draw(projection, "red")
ReflectedPoint
computes the reflected point about a line of a given point
ReflectedPoint(P, Line)
ReflectedPoint(P, Line)
P |
Vector containing the xy-coordinates of a point |
Line |
Line object previously created with |
Returns a vector which contains the xy-coordinates of the reflected point
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) xx <- c(0,1,2) yy <- c(0,1,0) P1 <- c(0,0) P2 <- c(1,1) Line <- CreateLinePoints(P1, P2) Draw(Line, "black") P <- c(-2,2) Draw(P, "black") reflected <- ReflectedPoint(P, Line) Draw(reflected, "red")
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) xx <- c(0,1,2) yy <- c(0,1,0) P1 <- c(0,0) P2 <- c(1,1) Line <- CreateLinePoints(P1, P2) Draw(Line, "black") P <- c(-2,2) Draw(P, "black") reflected <- ReflectedPoint(P, Line) Draw(reflected, "red")
ReflectedPolygon
creates the reflection about a line of a given polygon
ReflectedPolygon(Poly, Line)
ReflectedPolygon(Poly, Line)
Poly |
Polygon object, previously created with function |
Line |
Line object previously created with |
Returns the reflection of a polygon about a line
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) Draw(Poly, "blue") P1 <- c(-3,2) P2 <- c(1,-4) Line <- CreateLinePoints(P1, P2) Draw(Line, "black") Poly_reflected <- ReflectedPolygon(Poly, Line) Draw(Poly_reflected, "orange")
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) Draw(Poly, "blue") P1 <- c(-3,2) P2 <- c(1,-4) Line <- CreateLinePoints(P1, P2) Draw(Line, "black") Poly_reflected <- ReflectedPolygon(Poly, Line) Draw(Poly_reflected, "orange")
RemovePointPoly
creates a matrix to represent the polygon that connects several points
RemovePointPoly(Poly, position)
RemovePointPoly(Poly, position)
Poly |
Polygon object, previously created with function |
position |
Integer indicating the position of the point in the original polygon that is being removed. It is convenient to visualize the polygon with |
Returns a matrix which contains the points of the polygon. Each row represents one of the points
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) n <- 5 C <- c(0,0) l <- 2 Penta <- CreateRegularPolygon(n, C, l) Penta <- RemovePointPoly(Penta, 4) Draw(Penta, "blue", label = TRUE)
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) n <- 5 C <- c(0,0) l <- 2 Penta <- CreateRegularPolygon(n, C, l) Penta <- RemovePointPoly(Penta, 4) Draw(Penta, "blue", label = TRUE)
Rotate
rotates a geometric object of any of the following types: line, polygon or segment
Rotate(object, fixed, angle)
Rotate(object, fixed, angle)
object |
geometric object of type line, polygon or segment, previously created with any of the functions in the package |
fixed |
Vector containing the xy-coordinates of the only point of the plane which remains fixed during rotation |
angle |
Angle of rotation in degrees (0-360), considering the clockwise direction |
Returns a geometric object which is the rotation of the original one, following the clockwise direction
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) Draw(Poly, "blue") fixed <- c(-1,-1) angle <- 30 Poly_rotated <- Rotate(Poly, fixed, angle) Draw(Poly_rotated, "orange") fixed <- c(2,0) Poly_rotated <- Rotate(Poly, fixed, angle) Draw(Poly_rotated, "transparent")
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) Draw(Poly, "blue") fixed <- c(-1,-1) angle <- 30 Poly_rotated <- Rotate(Poly, fixed, angle) Draw(Poly_rotated, "orange") fixed <- c(2,0) Poly_rotated <- Rotate(Poly, fixed, angle) Draw(Poly_rotated, "transparent")
SelectPoints
allows the selection of points from the coordinate plane
SelectPoints(n)
SelectPoints(n)
n |
Number of points to select from the current coordinate plane |
Returns a vector or matrix which contains the xy-coordinates of the selected points. Each row represents one of the points. If n = 1
the output is a numeric vector, if n = 2
then it is a Segment
, and for n > 2
the object is a polygon.
n <- 3 points <- SelectPoints(n)
n <- 3 points <- SelectPoints(n)
ShearedPolygon
creates a sheared polygon from a given one
ShearedPolygon(Poly, k, direction)
ShearedPolygon(Poly, k, direction)
Poly |
Polygon object, previously created with function |
k |
Number that represents the shear factor which is applied to the original polygon |
direction |
String with value "horizontal" or "vertical" which indicates the direction in which shearing is applied. Horizontal means the shearing is parallel to the X axis, while vertical means parallel to the Y axis |
Returns a sheared polygon, in any of the two axis, to the original one
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) Square <- CreateRegularPolygon(4, c(-2, 0), 1) Draw(Square, "blue") k <- 1 Square_shearX <- Translate(ShearedPolygon(Square, k, "horizontal"), c(3,0)) Draw(Square_shearX, "orange") Square_shearY <- Translate(ShearedPolygon(Square, k, "vertical"), c(3,0)) Draw(Square_shearY, "orange")
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) Square <- CreateRegularPolygon(4, c(-2, 0), 1) Draw(Square, "blue") k <- 1 Square_shearX <- Translate(ShearedPolygon(Square, k, "horizontal"), c(3,0)) Draw(Square_shearX, "orange") Square_shearY <- Translate(ShearedPolygon(Square, k, "vertical"), c(3,0)) Draw(Square_shearY, "orange")
Sierpinski
plots the first iterations of Sierpinski triangle, a well-known fractal
Sierpinski(Tri, it)
Sierpinski(Tri, it)
Tri |
Regular triangle, previously created with function |
it |
Number of iterations to be performed for the construction of Sierpinski triangle. It is not recommended to choose a number higher than 10 in order to avoid an excess of computation |
None. It produces the plot of the first n
iterations of Sierpinski triangle in the current coordinate plane
http://mathworld.wolfram.com/SierpinskiSieve.html
x_min <- -6 x_max <- 6 y_min <- -6 y_max <- 6 CoordinatePlane(x_min, x_max, y_min, y_max) n <- 3 C <- c(0,0) l <- 5 Tri <- CreateRegularPolygon(n, C, l) it <- 6 Sierpinski(Tri, it)
x_min <- -6 x_max <- 6 y_min <- -6 y_max <- 6 CoordinatePlane(x_min, x_max, y_min, y_max) n <- 3 C <- c(0,0) l <- 5 Tri <- CreateRegularPolygon(n, C, l) it <- 6 Sierpinski(Tri, it)
SimilarPolygon
creates a sheared polygon from a given one
SimilarPolygon(Poly, k)
SimilarPolygon(Poly, k)
Poly |
Polygon object, previously created with function |
k |
Positive number that represents the expansion (k > 1) or contraction (k < 1) factor which is applied to the original polygon |
Returns a similar polygon, exapended or contracted, to the original polygon
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) Draw(Poly, "blue") k <- 2 Poly_similar <- SimilarPolygon(Poly, k) Draw(Translate(Poly_similar, c(-1,2)), "orange")
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) Draw(Poly, "blue") k <- 2 Poly_similar <- SimilarPolygon(Poly, k) Draw(Translate(Poly_similar, c(-1,2)), "orange")
Soddy
finds inner and outer Soddy circles of three given mutually tangent circles
Soddy(A, r1, B, r2, C, r3)
Soddy(A, r1, B, r2, C, r3)
A |
Vector containing the xy-coordinates of the center of circumference 1 |
r1 |
Radius for circumference 1 |
B |
Vector containing the xy-coordinates of the center of circumference 2 |
r2 |
Radius for circumference 2 |
C |
Vector containing the xy-coordinates of the center of circumference 3 |
r3 |
Radius for circumference 3 |
A list which contains the Soddy center and the radiuses of Soddy inner and outer circle of three mutually tangent circles
http://mathworld.wolfram.com/SoddyCircles.html
x_min <- -3 x_max <- 3 y_min <- -2.5 y_max <- 3.5 CoordinatePlane(x_min, x_max, y_min, y_max) A <- c(-1,0) B <- c(1,0) C <- c(0,sqrt(3)) r1 <- 1 r2 <- 1 r3 <- 1 Draw(CreateArcAngles(A, r1, 0, 360), "black") Draw(CreateArcAngles(B, r2, 0, 360), "black") Draw(CreateArcAngles(C, r3, 0, 360), "black") result <- Soddy(A, r1, B, r2, C, r3) soddy_point <- result[[1]] inner_radius <- result[[2]] outer_radius <- result[[3]] Draw(soddy_point,"red") Draw(CreateArcAngles(soddy_point,inner_radius,0,360),"red") Draw(CreateArcAngles(soddy_point,outer_radius,0,360),"red")
x_min <- -3 x_max <- 3 y_min <- -2.5 y_max <- 3.5 CoordinatePlane(x_min, x_max, y_min, y_max) A <- c(-1,0) B <- c(1,0) C <- c(0,sqrt(3)) r1 <- 1 r2 <- 1 r3 <- 1 Draw(CreateArcAngles(A, r1, 0, 360), "black") Draw(CreateArcAngles(B, r2, 0, 360), "black") Draw(CreateArcAngles(C, r3, 0, 360), "black") result <- Soddy(A, r1, B, r2, C, r3) soddy_point <- result[[1]] inner_radius <- result[[2]] outer_radius <- result[[3]] Draw(soddy_point,"red") Draw(CreateArcAngles(soddy_point,inner_radius,0,360),"red") Draw(CreateArcAngles(soddy_point,outer_radius,0,360),"red")
Star
creates a star with multiple building possibilities
Star(P, angle, l, time = 0, color = "transparent")
Star(P, angle, l, time = 0, color = "transparent")
P |
Vector containing the xy-coordinates of the starting point for the star |
angle |
Angle (0-360) that is related to the direction of the two segments which are drawn in each of the steps of the process. This parameter really represents the angle (in clockwise and anti-clockwise direction) for the two first drawn segments, but it is modified according to rotations of 144 degrees in all the following steps, including the last one, which closes the curve. |
l |
Number that indicates the length side of the segments that are drawn. This parameter will determine the size of the star |
time |
Number of seconds to wait for the program before drawing each of the segments that make star. If no |
color |
Color to indicate the points that are obtained during the process to draw the star. If missing, the points are not indicated and only the segments are drawn in the plot |
None. It produces the plot of a closed curve with the shape of a star, if the parameters are chosen properly
Abelson, H., & DiSessa, A. A. (1986). Turtle geometry: The computer as a medium for exploring mathematics. MIT press
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P <- c(0,0) angle <- 0 l <- 1 Star(P, angle, l)
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P <- c(0,0) angle <- 0 l <- 1 Star(P, angle, l)
Tessellation
creates a geometric pattern by the repetitive translation of an initial geometric object
Tessellation(objects_list, colors, direction, separation, it)
Tessellation(objects_list, colors, direction, separation, it)
objects_list |
A list composed by several geometric objects (mainly polygons created with |
colors |
Vector containing the colors for each of the objects of the initial geometric object |
direction |
Vector containing the xy-coordinates of the direction in which tessellation is being generated |
separation |
Number indicating the distance that separates any of the geometric objects in the repetitive pattern. This distance must be understood in the sense of a translation of the initial object. Indeed, this distance is only preserved in the direction of the chosen vector |
it |
Number of iterations to be performed for the construction of the tessellation |
None. It produces the plot of a repetitive pattern, usually known as a tessellation
http://mathworld.wolfram.com/Tessellation.html
x_min <- -6 x_max <- 6 y_min <- -2 y_max <- 10 CoordinatePlane(x_min, x_max, y_min, y_max) Hexa <- CreateRegularPolygon(6, c(-3,0), 1) Draw(Hexa, "purple") Tri <- CreatePolygon(c(-3,-1), c(Hexa[4,1],-2), c(Hexa[1,1],-2)) Draw(Tri,"pink") objects_list <- list(Tri, Hexa) cols <- c("pink", "purple") direction <- c(1,0) separation <- 1.732051 it <- 3 Tessellation(objects_list, cols, direction, separation, it) direction <- c(0,1) separation <- 3 it <- 4 Tessellation(objects_list, cols, direction, separation, it)
x_min <- -6 x_max <- 6 y_min <- -2 y_max <- 10 CoordinatePlane(x_min, x_max, y_min, y_max) Hexa <- CreateRegularPolygon(6, c(-3,0), 1) Draw(Hexa, "purple") Tri <- CreatePolygon(c(-3,-1), c(Hexa[4,1],-2), c(Hexa[1,1],-2)) Draw(Tri,"pink") objects_list <- list(Tri, Hexa) cols <- c("pink", "purple") direction <- c(1,0) separation <- 1.732051 it <- 3 Tessellation(objects_list, cols, direction, separation, it) direction <- c(0,1) separation <- 3 it <- 4 Tessellation(objects_list, cols, direction, separation, it)
Translate
translates a geometric object of any of the following types: line, polygon or segment
Translate(object, v)
Translate(object, v)
object |
geometric object, previously created with function |
v |
Vector containing the xy-coordinates of the translation vector |
Returns a polygon whose coordinates are translated according to vector v
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) Draw(Poly, "blue") v <- c(1,2) Poly_translated <- Translate(Poly, v) Draw(Poly_translated, "orange")
x_min <- -5 x_max <- 5 y_min <- -5 y_max <- 5 CoordinatePlane(x_min, x_max, y_min, y_max) P1 <- c(0,0) P2 <- c(1,1) P3 <- c(2,0) Poly <- CreatePolygon(P1, P2, P3) Draw(Poly, "blue") v <- c(1,2) Poly_translated <- Translate(Poly, v) Draw(Poly_translated, "orange")