Well I am finding a way to generate points equally distanced from each other in an area (or a polygon)
I find a very useful source of doing it
https://mathematica.stackexchange.com/questions/141184/how-to-generate-approximately-equally-spaced-points-efficiently
https://newbedev.com/how-to-generate-approximately-equally-spaced-points-efficiently
However, I do not code C, I literally can not understand (or convert it to python code).
I am definitely not a math guy, just a problem while coding that I need to find a solution.
If you can find any sources or have codes that can perform it please share it to me.
Related
I'm trying to build a simulation that will take place in a 1000x1000x1000 space. For each point in space, I need to be able to encode 2 or 3 properties.
I also need to be able to do some basic operations on the space, such as, given a point, find the properties of the 26 adjacent 3D neighbors of the point.
All points will lie on vertices in the 1000x1000x1000 space (i.e. every point is discrete).
I wrote up a version in python using numpy and it is much too slow. I've also looked for libraries that would speed it up but couldn't find anything.
Does anyone know of a python library that would provide useful helper functions and would be appropriate for a simulation of this size?
Using Numpy to together with the Numba python-compiler for the more intricate algorithms can take you a long way.
Also, I think you are refering to a "stencil" algorithm, and numba has specific stencil-functionality that could help you.
But start with a smaller grid during development!
I am plotting some geometry on an image. The problem is the coordinates are coming out as floats, so I am not able to plot them. As a work around I am using floor(); to truncate it to nearest Integer. This works fine in some cases, except that it shifts my image a little bit.
x=9.7
x'=floor(x)= 9 //the plot is now at 9 and not at 9.7 as desired, (this is 'shift')
But in cases where my requirement is to draw multiple shapes at equal distance I am facing problem as the shift (because of floor();)is not uniform for each shape.
It is just like quantization noise in digital communication.
Is there any way I can get around this problem ?
This problem is actually quite a common one in computer graphics. Rasterisation is the problem domain you are currently struggling with. You may find Bresenham's line algorithm a good introduction to the topic. Here is a nice interactive site with a few different rasterisation algorithms.
Hope that helps!
I have data about 10 points in a 2D map, I know the location of points 1,2 and 3. I also know the distance between point 1,2 and 3 to all other points.
I know that cell phone uses distance from gsm towers to locate their location. I wish to use similar approach to locate points 3-10. How can I implement such a solution with python? Which libraries can I use?
Thank you for all help
First, solve the math. Make a drawing. You will find that you can use two points and their distance to reduce the possible points to just two, the third one will only be needed to disambiguate between the two. Putting the whole into Python should be easy then.
Note that I'm not going to spell this out completely for you, because it is customary to not spoil other programmers the experience of doing their own homework, doing research etc. If you have something that you have a problem with, then ask specific questions and demonstrate some effort on your side first.
I'm interested in using python to make diagrams representing the size of values based on the size of squares (and optionally their colour). Basically I'm looking for a way to make overviews of a bunch of values like the good old program windirstat does with hard-drive usage (it basically makes a big square representing your harddrive and then smaller squares making up the area inside of it representing different programs, the bigger the square the larger the file, colour indicates the type of file). I'm fairly familiar with matplotlib, and I don't think it's possible to do something like this with it. Is there any other python package that would help? Any suggestions for something more low level if it's not? I guess I could do it manually if I could find a way to draw the boxes programatically (I don't really care about the format, but the option to export SVG as well as PNG would be nice).
Ultimately, it would be nice to have it be interactive like windirstat is, where if you were to hover over a particular square you get more information on it, and if you clicked on it maybe you'd go in and see the makeup of that particular square. I'm only familiar with wxpython for GUI stuff, not sure if it could be used for something like this. For now I'd be happy with just outputting them though.
Thanks a lot!
Alex
Edit:
Thanks guys, both your answers helped a lot.
You're looking for Treemapping algorithms. Once implemented, you can transform the output (which should be rectangles) into plotting commands to anything that can draw layered rectangles.
Edit:
More links and information:
If you don't mind reading papers, the browser-based d3 library provides for 'squarified' treemaps (js implementation). They reference this paper by Bruls, Huizing, and van Wijk. (This is also citation 3 on the wikipedia article)
I'd search on the algorithms listed on the linked Wikipedia article. For instance, they also link to this article, which describes an algorithm for "mixed treemaps". The paper also includes some interesting portions at the end describing transformations into other-than-rectangular shapes.
Squarified certainly appears to be the most common variety around. The above links should give you enough to work towards a solution or, even, directly port the d3 implementation. However, the cost of grokking d3's model (which is something like a declarative form of jQuery) may be somewhat high. At first glance, though, the implementation appears relatively straightforward.
Squaremap does this. I haven't used it (I only know it from RunSnakeRun) and its documentation is severely lacking, but it seems to work.
I'm writing a program in Python. I have a series of shapes (polygons, defined as a sequence of coordinate pairs) and I need to tell if they overlap a particular rectangle.
Is there an easy algorithm for handling this? Or, better, is there a pure Python library that can handle these calculations for me?
Presuming your "arbitrary shapes" are indeed polygons (given that they're described as coordinate pairs), determining if they overlap (in any language) is a relatively trivial calculation. You merely need to compute if any side of polygon A intersects any other side of polygon B.
If you need an example, there's a rather thorough walkthrough at the Drexel Math Forum.
There are a number of Python modules which can assist you in this pursuit, such as Sympy, Numpy, PyGame, etc., but all of them are rather heavy if this is the only geometric calculation you need to make.