Where can I plot large number of spheres given (x,y,z,r) coordinates? - plot

My problem is the following one: I have a file with (x,y,z) coordinates of position of the center of some spheres and in the last column I have de radius r. What I want to do is to plot it in a similar way like the following image:
Does someone know which software can I use to do that? The number of spheres I have is LARGE (like 600000 spheres)
Thanks.

Related

Transform 3D Points to 2D with a specific camera position

I have a matrix that contains the points of the form (x,y,z). My goal now is to transform these points so that they lie in the 2D plane. I want to keep the angle as shown in the figures. Im working with R and want to use ggplot2 instead of the plotly package.
Can anyone help me with this?

Distributing points evenly spaced within a sphere

I am looking for an algorithm to distribute a bunch of points (could be anywhere from a few hundred to millions) within a sphere. In this case the sphere is centered at (0,0,0).
For random points a simple method is
repeat
x:=random*diameter-radius;
y:=random*diameter-radius;
z:=random*diameter-radius;
until ((x*x+y*y+z*z)<(radius*radius));
But I want to get the points evenly spaced within the sphere and without bunching at the poles.
Any good tricks/algorithms/formulas/code snippet to accomplish this?
You could do something like this:
Put the center of your sphere at a random position within an infinite volume of evenly-spaced points, like a tetrahedral or cubic lattice.
Enumerate points in order of increasing distance from the center until you have the right number.
Rescale the selected points around the center so that the distance to the furthest point is equal to the desired radius.
If you need evenly spaced points - just place them in grid nodes.
Sphere with radius R has volume
V=4/3*Pi*R^3
so for placing N points every cell of cubic grid (perhaps you might want to use hexagonal close packing) should have volume
v=4/3*Pi*R^3/N
and edge length
l = R * (4*Pi/(3*N))^1/3
Then generate points in coordinates (a*l, b*l, c*l) where a,b,c are integers limited by -R..+R (with appropriate sum of squares).
Proposed approach is quite rough estimation and perhaps some points from N needed ones might run outside of the sphere. In this case one have to diminish cell size or use more exact value - it might be calculated using 3D analog of Gauss circle formula ()
Thanks for the explanation by joriki. The above formula has been explained in proof of the formula mentioned. But the formula has some limitations. The cube length can be 2 (-1 to 1 in all directions). From the above concept, mentioned by joriki or proof of the formula mentioned we can generalize for the cube of any length (i.e 2a (-a to a in all directions)). Here 2a is the side length of the cube.
$a^6-(a^2-x^2 )(a^2-y^2)(a^2-z^2)=x^2 a^2 (a^2-\frac{z^2}{2}-\frac{y^2}{2}+\frac{y^2 z^2}{3a^2})+y^2 a^2 (a^2-\frac{z^2}{2}-\frac{x^2}{2}+\frac{x^2 z^2}{3a^2})+z^2 a^2 (a^2-\frac{x^2}{2}-\frac{y^2}{2}+\frac{y^2 x^2}{3a^2})$
$x'=xa \sqrt{a^2-\frac{z^2}{2}-\frac{y^2}{2}+\frac{y^2 z^2}{3a^2}}$,
$y'=ya \sqrt{a^2-\frac{z^2}{2}-\frac{x^2}{2}+\frac{x^2 z^2}{3a^2}}$,
$z'=za \sqrt{a^2-\frac{x^2}{2}-\frac{y^2}{2}+\frac{y^2 x^2}{3a^2}}$,
From the above equation, we can easily separate the (x',y',z') as explained in 1. The above equation will readily find the mapping of the generalized length of the cube to a sphere. I hope this will be helpful.
Form the above equation we can also find the evenly distribution of points within the sphere by varying the grid size of the cube. By discretizing the cube into different grids and simultaneously mapping into the sphere will give the evenly distribution of points within the sphere.
Kindly ignore some typos.
C++ code for evenly distributing points within the sphere:-
for(x=-a;x<=a;x=x+n)
for(y=-a;y<=a;y=y+n)
{
for(z=-a;z<=a;z=z+n)
{
xnew=x*a*(sqrt((a*a)-(y*y)/(2)-(z*z)/(2)+(y*y*z*z)/(3*a*a)));
ynew=y*a*(sqrt((a*a)-(z*z)/(2)-(x*x)/(2)+(x*x*z*z)/(3*a*a)));
znew=z*a*(sqrt((a*a)-(x*x)/(2)-(y*y)/(2)+(y*y*x*x)/(3*a*a)));
cout<<" "<<xnew<<" "<<ynew<<" "<<znew<<endl;
}
}
}
Note:- Here in code, n is the grid size of a cube.

Building a 3d plot function for Antenna Emission Measurements

I have an input of three [1:360,2] tables that include measurements of the three planes X,Y,Z with each plane having 1:360 degree polar coordinates. A good example of one of those tables being the image here.
image example
I would like to print those three "circles" as different planes circles (x,y,z) as is shown in the link below.
click here
I wrote last night a small example that works on the rgl library (but perhaps
I should "move" this code to the ggplot2) that plots those three circles by converting the polar coordinates to cartesian ones, for simplicity assume that all three circles have radius of 1. You can copy paste the below and see what I mean
require("rgls")
degreeToRadian<-function(degree){
return (0.01745329252*degree)
}
turnPolarToX<-function(Amplitude,Coordinate){
return (Amplitude*cos(degreeToRadian(Coordinate)))
}
turnPolarToY<-function(Amplitude,Coordinate){
return (Amplitude*sin(degreeToRadian(Coordinate)))
}
# first circle
X1<-turnPolarToX(1,1:360)
Y1<-turnPolarToY(1,1:360)
Z1<-rep(0,360)
# second circle
X2<-turnPolarToX(1,1:360)
Y2<-rep(0,360)
Z2<-turnPolarToY(1,1:360)
# third circle
X3<-rep(0,360)
Y3<-turnPolarToX(1,1:360)
Z3<-turnPolarToY(1,1:360)
Min<-min(X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3)
Max<-max(X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3)
plot3d(X1,Y1,Z1,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=FALSE,add=TRUE,col="red",type="l")
plot3d(X2,Y2,Z2,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=FALSE,add=TRUE,col="green",type="l")
plot3d(X3,Y3,Z3,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=TRUE,add=FALSE,col="blue",type="l")
the problem I have now is that the axes contain cartesian coordinate values that are not understandable by the user. I am thinking of how I can remove the cartesian coordinates and use colors that considers the amplitude value (of the initial information at polar corrdinates) of each vector instead of the x,y values)
I would like to thank you in advance for your reply
Regards
Alex

Using point coordinates and diameter to calculate areal projection of points

I have data on a number of ecological variables associated with spatial points. Each point has x & y coordinates relative to the bounding box, however the points represent circular areas of varying diameter. What I'm trying to achieve is to project the area occupied by each point onto the observation window so that we can subsequently pixellate the area and retrieve the extent of overlap of the area of each point with each pixel (grid cell). In the past I have been able to achieve this with transect data by converting to a psp line object and then using the pixellate function in the spatstat package but am unsure how to proceed with these circular areas. It feels like I should be using polygon classes but again I am unsure how to define them. Any suggestion would be greatly appreciated.
In the spatstat package, the function discs will take locations (x,y) and radii r (or diameters, areas etc) and generate either polygonal or pixel-mask representations of the circles, and return them either as separate objects or as a single combined object.

Disperse points in a 2D visualisation

I have a set of points like this (that I have clustered using R):
180.06576696, 192.64378568
180.11529253999998, 192.62311824
180.12106092, 191.78020965999997
180.15299478, 192.56909828000002
180.2260287, 192.55455869999997
These points are dispersed around a center point or centroid.
The problem is that the points are very close together and are, thus, difficult to see.
So, how do I move the points apart so that I can distinguish each point more clearly?
Thanks,
s
Maybe I'm overlooking some intricacy here, but...multiply by 10?
EDIT
Assuming the data you listed above are Cartesian (x,y) coordinate pairs, you can visualize them as a scatter plot using Google Charts. I've rounded your data to 3 decimal places, because Google Charts doesn't appear to handle higher precision than that.
I don't know the coordinates for your central point. In the above chart, I'm assuming it is somewhere nearby and not at (0,0). If it is at (0,0), then I imagine it will be difficult to visualize all of the data at once without some kind of "zoom-in" feature, scaling the data, or a very large screen.
slotishtype, without going into code, I think you first need to add in the following tweaking parameters to be used by the visualization code.
Given an x by y display box, fill the entire box, with input parameters [0.0 to 1.0]...
overlap: the allowance for points to be placed on top of each other
completeness: how important is it to display all of your data points
centroid_display: how important is it to see the centroid in the same output
These produce the dependent parameter
scale: the ratio between display distances to numerical distances
You will need code to
calculate the distance(s) to the centroid like you said,
and also the distances between data points, affecting the output based on the chosen input parameters.
I take inspiration from the fundamentals in the GraphViz dot manual. Look at the "Drawing Orientation, Size and Spacing" on p12.

Resources