How can I generate randomly placed spheres in a 3dbox with python - list

I have created a 3d box (2050, 700, 650) with python and I have 3 panels inside of it, which divide the box in 3 smaller boxes. Inside the middle box I want to create random placed spheres. So far in order to create the box, the panels, the spheres etc I use a library called smoldyn.
For example its sphere object can be defined like this: sph1 = smoldyn.Sphere(center=[1162, 563, 569], radius=5, slices=50, stacks=50), where you can see the center, radius, slices, stacks etc.
I could do it manually and write countless lines of code but is hard and very time consuming.
How can I create randomly placed spheres in the middle part of my big box?
Thank you !

Related

Divide 2d Matrix into different rectangles C++

I want to create c++ code that get all different rectangles within 2d matrix
i need to get all cases for example the left part of the picture i got all vertical rectangles and the right picture i got some vertical and some horizontal
i need to get all possible ways like picture
in other way i need to have output like that
array each element within it have array of objects every object have the start of the rectangle and the end of it say (0,0) to (0,3)

Creating deformable map in root TCanvas

I have some data that I'm plotting on a TH2F through the command-line interface of ROOT. I have a TTree* called goodtree, and I plot the XY positions of events in a detector as follows:
root [1] TCanvas *can = new TCanvas("can","can",800,800)
root [2] goodtree->Draw("y:x>>h1(400,-200,200,400,-200,200)","r<200","colz")
I also want to make normalized area plots, by looking at r^2 versus theta:
root [3] goodtree->Draw("r*r:t>>h2(400,-3.14,3.14,400,0,41000)","r<200","colz")
This part is fine. What I want to do next is overlay a map onto the XY plot, and have it automatically deform to the correct positions on the R^2T plot. What I mean is, this is a particle detector and uses photomultiplier tubes (PMTs) which have a circular cross-section in XY. I want to be able to overlay a map onto h1 which shows the outlines of these PMTs (which are in a honeycomb pattern). This I can also do very quickly with a script.
The tough bit is that I want to be able to define this map in XY, and plot it overtop of the R^2T data points. Is there a way do do this easily without having to calculate the positions, widths, and heights of all of these deformed ellipses by hand?

Drawing lines with dimensions In Livecode

I am trying to write a small drawing program with Livecode, that will show the length of the drawn line over the line so it is available for editing, I also need to display the angles of the polygon for editing. The user should be able to select one section of the polygon by clicking on the dimension. This will load the length of the line into the field on the right for editing. Once the correct number is entered the drawing will redraw itself. (I can probably figure this part out using the "points" of the polygon) I have included a screen shot of what the program should look like. I was hoping that it would display these figures as the image was being drawn by the user. I am sorry I have not included any code, however I don't even know where to start. I have written several programs involving databases, but this is my first attempting to use drawings. Thanks in advance for any advice!! http://i.stack.imgur.com/gfKS9.jpg
To get the angle you can use some trigonometry. if you have two points (which you can get by using
the points of graphic "myPolygon"
Then you get one point per line. If you want to calculate the angle between two points you can use some trigonometry. If you have a point x1, y1 and another point x2,y2 you get the angle by using
put atan2(y2-y1, x2-x1) into tRad
The angle will be in radians from -pi to +pi so you need to convert it to degrees if you want more "regular" degrees:
put tRad*180/pi into tDeg
The angle you get is according to the x-y coordinate system. So if you want the angle between to lines you need to do two calculations and add the angles.
You can't change the size of a single segment but all polygon.
To change the size of the line...
set the linesize of graphic "polygon" to 4
Paolo

I have a large list of bounding boxes, how can I calculate duplicates?

I have a list of bounding boxes, I was wondering how I could calculate which ones were redundant / duplicates.
The reason being is I have 2 million of these I send to a API and I want to know which are overlapping others so I can reduce them down so each box only covers a unique area of land, so no two bounding boxes cover the same piece of geo space.
How would I calculate it so that these bounding boxes were each covering their own unique space of geo land ?
I am writing this program in C++ btw.
I think that this task is more complex then you think.
You would have to split existing boxes, untill no overlapping exists, and then remove the boxes totally contained in another.
Instead giving you a solution to that, I recomend to check if you can live with:
1) remove the boxes that are totally contained in another box.
2) leave (partly-)overlapping boxes as they are.
For 2 millions you need a spatial index (QuadTree), to get a list of all boxes nearby one box.
If you have to avoid any overlappings, then you must continue to think what should be the result?
A) A union of overlapping rectangles that therfore is not an rectangle anymore, but a polygon.
or B) The result should be rectangles.
You could check if X% of a box's vertices are inside another box to find if it's overlapped but I suppose this isn't the optimal solution.

Drawing application with OpenGL/Openframeworks

I'm trying to program a brush stroke/drawing application using OpenGL within Openframeworks. For now I'm just trying to create squiggly lines that follow your mouse.
I've started by using ofpolyline but I have just managed to create a straight line that follows my mouse. I would really appreciate some pseudo code or something to point me in the right direction.
start. set (mouseX,mouseY);
end.set(mouseX,mouseY);
ofPolyline myline;
myline.addVertex(start.x,start.y);
myline.curveTo(end.x,end.y);
myline.bezierTo(mouseX,mouseY, mouseX,mouseY,mouseX, mouseY);
myline.addVertex(end.x,end.y);
myline.draw();
A Bezier curve with two vertices is always just a straight line segment. You need to add more vertices/control points to get non-degenerate (round) curves. So you could store the last mouse position somewhere, and add a new vertex when the mouse was moved by a certain amount (eg 20 pixels). Or add a vertex when the user clicks. However, if you always just call bezierTo(x,y,x,y,x,y), you will still only get straight lines. You need to offset the two control points from (x,y) to get round curves.