Points of intersection in R - r

This might be a stupid question...
I've two vectors containing Y coords
X is simply 1:8
I've added the lines to a plot area and would like to identify the point of intersection of the two lines.
Is there a default package to find this?
Thanks

The intersection of two lines is found analytically by solving the two linear equations which define the lines. I'll leave the math as an exercise to the OP.
If you want to use a very helpful and powerful package, you could read up on the package spatstat . Once you've converted your lines into psp objects, use spatstat:crossing.psp to find intersections.

Related

Creating a ternary plot from Cartesian coordinates

I am trying something - I want to estimate contributions from sources via a mixing triangle.
I have all data points in the Cartesian system (2 tracers measured)
Now I need to transform my coordinates into trilinear coordinates.
I was looking for a pre-existing function for that or another way to compute it on my own.
Can someone help me? Is there something existing already in R?
ggtern needs those trilinear coordinates if I did not misunderstood the manual.
Thanks,
Nadine

How to find boundary for set of points in R?

I have a data set of XYZ coordinates (lake bathymetry) and I want to create a grid out of them for later meshing purposes using GMSH. I know that there is an easy way to do it in MATLAB using the boundary(x,y,z) function. Unfortunately, I couln't find anything similar in R and I have too many points to create boundary lines by hand.
Does anyone has an idea how to proceed with this in R? At the end I need the lines consisting of the outer points in my point cloud.
Thanks a lot!
You can try using chull which finds the convex hull.
From the chull help
X <- matrix(stats::rnorm(2000), ncol = 2)
chull(X)
plot(X[,1],X[,2])
points(X[chull(X),1],X[chull(X),2],col=2,pch=19)

Suggested package/function to compute the vertices of a 3-simplex (tetrahedron)

I'd like to draw the 3-simplex which encloses some random points in 3D. So for example:
pts <- rnorm(30)
pts <- matrix(pts, ncol = 3)
With these points, I'd like to compute the vertices of the 3-simplex (irregular tetrahedron) that just encloses these points. Can someone suggest a package/function that will do this? All manner of searching for simplex-related material is dominated by answers that relate to using simplices for other purposes, of which there are many. I just want to compute one and draw it. Seems simple, but I don't seem to know the relevant keywords for what I need.
If nobody can find a suitable package for this, you'll have to settle for doing it yourself, which isn't so difficult if you don't require it to be the absolute tightest fit. See this question over at mathexchange.
The simplest approach presented in this question seems to me to be translating the origin so that all points lie in the positive orthant (i.e, all point dimensions are positive) and then projecting the points to lie within the simplex denoted by each unit vector. To get this simplex in your original coordinate system you can take the inverse projection and inverse translation of the points in this simplex.
Another approach suggested there is to find the enveloping sphere (which you can for instance use Ritter's algorithm for), and then find an enveloping simplex of the sphere, which might be an easier task depending what you are most comfortable with.
I think you're looking for convhulln in the geometry package, but I'm no expert, so maybe that isn't quite what you are looking for.

Determine the points in the boundary of a given region in 2D

What is a good way to determine the points in the boundary of a given region in 2D?
Suppose that you are given a nested list with lists of two coordinates, e.g.
{ {x1,y1}, {x2,y2}, {x3,y3} }
Of course the actual nested list would have a lot more points than 3, which are associated to a given region in the plane. The nested list, for example, could determine a disk in the plane. Then, the output should be a nested list corresponding to a circle.
I don't want any image recognition stuff applied to a possible plot. I would like operations on the nested list.
This answer is based on #andand comment. The credit is all his.
If I have a nested list called "region", with lists of the 2d coordinates, I would get the "convex hull" of it writing
Needs["ComputationalGeometry`"]
regionhull = ConvexHull[ region ]
But "ConvexHull" gives us the indices of the lists within the nested list, in counterclockwise order, corresponding to the convex boundary of the region. Thus, an adittional step is needed, to make the needed output:
regionboundary = region[[ regionhull ]]
But still, this answer is incomplete. It seems to me that a "concave hull" algorithm would be the more general solution. Would anyone know anything about the concave hull in Mathematica? I may post an additional question for that.
Below, I show a figure to understand the concave and convex hull algorithms extracted from
https://gis.stackexchange.com/questions/1200/concave-hull-definition-algorithms-and-practical-solutions
A tutorial for the "Computational Geometry Package" is found at
http://reference.wolfram.com/mathematica/ComputationalGeometry/tutorial/ComputationalGeometry.html
** Addendum **
The package "alphahull" can solve the problem of finding the boundary of a concave region. Its description is found here:
http://cran.r-project.org/web/packages/alphahull/vignettes/alphahull.pdf
Sounds like you want some kind of interpolation technique. http://en.wikipedia.org/wiki/Interpolation

quality analysis of fitted pyramid

sorry for posting this in programing site, but there might be many programming people who are professional in geometry, 3d geometry... so allow this.
I have been given best fitted planes with the original point data. I want to model a pyramid for this data as the data represent a pyramid. My approach of this modeling is
Finding the intersection lines (e.g. AB, CD,..etc) for each pair of adjacent plane
Then, finding the pyramid top (T) by intersecting the previously found lines as these lines don’t pass through a single point
Intersecting the available side planes with a desired horizontal plane to get the basement
In figure – black triangles are original best fitted triangles; red
and blue triangles are model triangles
I want to show that the points are well fitted for the pyramid model
than that it fitted for the given best fitted planes. (Assume original
planes are updated as shown)
Actually step 2 is done using weighted least square process. Each intersection line is assigned with a weight. Weight is proportional to the angle between normal vectors of corresponding planes. in this step, I tried to find the point which is closest to all the intersection lines i.e. point T. according to the weights, line positions might change with respect to the influence of high weight line. That mean, original planes could change little bit. So I want to show that these new positions of planes are well fitted for the original point data than original planes.
Any idea to show this? I am thinking to use RMSE and show before and after RMSE. But again I think I should use weighted RMSE as all the planes refereeing to the point T are influenced so that I should cope this as a global case rather than looking individual planes….. But I can’t figure out a way to show this. Or maybe I should use some other measure…
So, I am confused and no idea to show this.. Please help me…
If you are given the best-fit planes, why not intersect the three of them to get a single unambiguous T, then determine the lines AT, BT, and CT?
This is not a rhetorical question, by the way. Your actual question seems to be for reassurance that your procedure yields "well-fitted" results, but you have not explained or described what kind of fit you're looking for!
Unfortunately, without this information, your question cannot be answered as asked. If you describe your goals, we may be able to help you achieve them -- or, if you have not yet articulated them for yourself, that exercise may be enough to let you answer your own question...
That said, I will mention that the only difference between the planes you started with and the planes your procedure ends up with should be due to floating point error. This is because, geometrically speaking, all three lines should intersect at the same point as the planes that generated them.

Resources