Export x/y coordinates of Delaunay triangles vertices using deldir in R - delaunay

How would I generate a data frame with the following data in R using deldir?
A row for each Delaunay triangle
The x1, y1, x2, y2, x3, y3 coordinates for the vertices of each triangle
I've gone through the Reference manual, but it only seems to allow for an output of the indices of the vertices - not the coordinates.

Related

How to plot a graph of points generated by two vectors in Julia?

I have two vectors where each corresponding position of each vector represents a point, for example position 1 of one vector has a value of x1 and position 1 of the other vector has a value of y1, and these values (x1 , y1) represent a point. And so on with the points (x2, y2), (x3, y3)... I need to plot a graph with this set of points.
How can I do this in Julia?
You just do scatter(x,y) to draw the points
x = [1,2,3,4];
y = [4,7,5,9];
using Plots
scatter(x,y; legend=:topleft)

3D Vector coordinates from x and y rotation

I tried to google this question several times, but i found only articles about "Rotation matrix".
I have 3d coordinate system and two angles: α for x-rotation and β for y-rotation (I'm not sure if I've positioned the angles correctly in the diagram).
And i need to find coordinates of Vector(x_1, y_1, z_1)
Please, help me to figure out the formulas.
Let's break this up into two transformations.
Starting with your unit vector at (0,0,1), we'll apply the alpha transformation first.
You can treat the rotation about the y-axis as a 2-D transformation and ignore the y-axis entirely. Then it becomes simple trig to get the x and z components with cos and sin of your transformation angle (alpha). We know the length of the vector is 1 since it's a unit vector, but your vector could be any length -- just multiply the cos and sin equations by the length of your vector.
This first transformation leaves us with this formula:
(x1, y, z1) => (sin(alpha), 0, cos(alpha))
Assume your transformation angle starts on the +z axis and as it increases, the angle moves counterclockwise around the y-axis (or on the XZ plane).
For the second transformation, We're rotating around the axis perpendicular to our vector. We will do something very similar, but this time substituting x1 and z1 for our new values sin(alpha) and cos(alpha).
Getting y1 is as simple as taking the sin of your beta angle like before, but transforming x1 and z1 requires us to scale x1 and z1 by the cosine component of this triangle. This is because the relationship between x1 and z1 does not change as we rotate around their perpendicular axis.
Imagine a circle with the center at the origin and a single point on its circumference at (x1, 0, z1). As we rotate the vector around that circle, x1 and z1 scale relative to the center point, but their ratio does not change.
All we have to do is scale both numbers by the cosine component of our beta angle. I labeled that omega here.
This leaves us with a final formula of
(x2, y1, z2) => (cos(beta)*sin(alpha), sin(beta), cos(beta)*cos(alpha))

3d points to rotation matrix of orientation

I have 2 3d points:
point1 = (x1, y1, z1).
point2 = (x2, y2, z2).
I want to calculate the rotation matrix R of orientation of the vector between this two points.
The translation of this vector is:
A = (x1-x2, y1-y2, z1-z2).
How I can calculate this? (In easy and efficient calculation/implement).
c++ code is optional.
I am using Egan and GTSAM libraries.

How to find the lattice points between two given coordinates

Let's say that I am given two coordinates (A and B) on a 2D plane. Is there a mathematical formula to calculate the coordinates of all the lattice points between A and B? I've been looking forever but can't find anything.
Thank you in advance!
The line between two arbitrary points on a plane will not pass through any integer lattice points in general. However, you can generate a list of "nearby" lattice points by looping between the integer x values in between x1 and x2 to find corresponding nearby integer y values and then looping over integer y values between y1 and y2 to find corresponding nearby integer x values.

Draw multiple 3D boxes of different dimensions and coordinates in R

Recently I stumbled over the rgl-Package in R, which can be used to create interactive 3d plots. Now I want to visualize a set of boxes in one 3d plot. A Box B has cartesian coordinates B_coord=[x,y,z], which correspond to the lower left back corner and dimensions B_dim=[x1,y1,z1].
Apparently it is easy to draw, scale and position some cubes with the following exemplary code:
open3d()
printBox <- function(x,y,z,x1,y1,z1) {
mycube <- scale3d(cube3d(),x1,y1,z1)
wire3d(translate3d(mycube,x,y,z))
}
printBox(0,0,0,1,1,1)
With this code the boxes are moved to x,y,z and scaled to x1,y1,z1. My question is how to write a similar function with the same input which positions the boxes by the coordinates of their lower left back corner and draws a box with the dimensions x1, y1, z1. I am not tied to the rgl package and R, but I like its interactive 3d view.
Thank you for your ideas!
I think your code already does that. So as to make it more clear, and explain what those rgl functions do, I unrolled your function and commented it and put it in a more illustrative example.
library(rgl)
open3d()
# create and plot a box at (x,y,z) of size (x1,y1,z1)
printBox <- function(x, y, z, x1, y1, z1) {
mycube <- cube3d() # create a cube as mesh object
mycube <- scale3d(mycube, x1, y1, z1) # now scale that object by x1,y1,z1
mycube <- translate3d(mycube, x, y, z) # now move it to x,y,z
wire3d(mycube) # now plot it to rgl as a wireframe
}
# Display 5 boxes along a diagonal line
n <- 5
for (i in 1:n) {
x <- i/n
y <- i/n
z <- i/n
sz <- 1/(2*n)
printBox(x, y, z, sz,sz,sz )
}
axes3d() # add some axes

Resources