Skip to content

Commit

Permalink
Reworked grid plot to show reference and actual positions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver-Loeffler committed Jan 29, 2025
1 parent ec63956 commit dab4765
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
Binary file modified example-non-modular/grid_plot_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified example-non-modular/grid_plot_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example-non-modular/grid_plot_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 41 additions & 10 deletions example-non-modular/src/main/R/Helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ add_noise <- function(sample, noise=1) {
#' @param pitch pitch
#' @param noise standard deviation (sd) for the rnorm function
#' @return data.frame with refx, refy, posx, posy and diffx, diffy columns, plus a type column
generate_grid <- function(l=-2,u=2,pitch=1000, noise=1) {
generate_grid <- function(l=-2,u=2,pitch=1000, noise=0.01) {
x_rng=(l:u)*pitch
y_rng=(l:u)*pitch
result <- do.call(rbind,lapply(x_rng, FUN=generate_sub_grid, y_rng))
Expand All @@ -50,35 +50,66 @@ generate_grid <- function(l=-2,u=2,pitch=1000, noise=1) {
#' Generates a grid plot for the given data.frame.
#' @param R data.frame with refx, refy, posx, posy
#' and diffx, diffy columns, plus a type column
plot_distortion_grid <- function(R) {
#' @param margin Plot margin (percentage of )
plot_distortion_grid <- function(R, margin=0.1) {
# R must have:
# x,y = Design Coordinates
# posx, posy = Actual Coordinates
# dx, dy = Displacement, e.g. dx = posx - x
mg <- max(abs(range(R$refx)))*margin
x_extent <- c(min(R$refx)-mg, max(R$refx)+mg)

mg <- max(abs(range(R$refy)))*margin
y_extent <- c(min(R$refy)-mg, max(R$refy)+mg)

# Connect all points in column
plot(R$posy ~ R$posx,
plot(c(R$posy,R$refy) ~ c(R$posx,R$refx),
xlab = "X position",
ylab = "Y position",
main = "Displacement Grid Plot")
main = "Displacement Grid Plot", col="lightgray", pch=3, lwd=0.1, cex=0.1, xlim=x_extent, ylim=y_extent)

rows <- unique(R$refx)
for (r in rows) {
all_points <- R[which(R$refx == r),]
lines(all_points$refy ~ all_points$refx, col="lightgray")
}

# Connect all points in row
rows <- unique(R$refy)
for (r in rows) {
all_points <- R[which(R$refy == r),]
lines(all_points$refy ~ all_points$refx, col="lightgray")
}

rows <- unique(R$refx)
for (r in rows) {
all_points <- R[which(R$refx == r),]
lines(all_points$posy ~ all_points$posx)
lines(all_points$posy ~ all_points$posx, col="blue")
}

# Connect all points in row
rows <- unique(R$refy)
for (r in rows) {
all_points <- R[which(R$refy == r),]
lines(all_points$posy ~ all_points$posx)
lines(all_points$posy ~ all_points$posx, col="blue")
}
}


plot_distortion_grid(generate_grid(noise=200))
# Some Demo Code
if (FALSE) {
plot_distortion_grid(generate_grid(noise=200))

png("grid_plot_1.png")
plot_distortion_grid(generate_grid(l=-2.5,u=2.5,noise=100))
dev.off()

png("grid_plot_2.png")
plot_distortion_grid(generate_grid(l=-4.5,u=4.5,noise=100))
dev.off()

png("grid_plot_3.png")
plot_distortion_grid(generate_grid(l=-7.5,u=7.5,noise=100))
dev.off()
}

png("grid_plot.png")
plot_distortion_grid(generate_grid(l=-10,u=10,noise=100))
dev.off()

0 comments on commit dab4765

Please sign in to comment.