computational-geometry

Least distance from a point to an area

若如初见. 提交于 2019-12-05 15:47:25
I am trying to find a point (P2) in a closed area that has the minimum distance to a point (P1). The area is built of homogenous pixels, it is not shaped perfectly and it is not necessarily convex. This is basically a problem of reaching an area from the shortest path. The whole space is a stored in the form of a bitmap in the memory. What is the best method to find P2? Should I go with random search (optimization) methods? Optimization methods do not give the exact minimum but they are faster than brute forcing every pixel of the area. I need to perform thousands of these decisions in a few

Calculate volume of 3D mesh

若如初见. 提交于 2019-12-05 09:06:36
问题 i get tired to calculate the volume of 3D object (Cube, Cylinder ...) can any one help with this problem ? the question is , how to calculate the volume of object from his coordinates based on triangles. my class don't do well the job , any one help me to emproove the class ? thanks public class Algorithm { private Mesh _mesh { get; set; } public Algorithm(Mesh mesh) { _mesh = mesh; } private double SignedVolumeOfTriangle(Vector3 p1, Vector3 p2, Vector3 p3) { var v321 = p3.X * p2.Y * p1.Z;

Transforming coordinates of one rectangle to another rectangle

和自甴很熟 提交于 2019-12-05 09:01:37
in the above image I have shown two rectangles rectangle 1 whose x can vary from -900 to 13700 and Y can vary from -600 to 6458 rectangle 2 whose coordinate X can vary from 0 to 3000 and y can vary from 0 to 2000 Also: rectangle 2 has its starting point at left top position(0,0) whereas rectangle 1 has starting point( width/2, height/2). What I need to do : to convert a point of rectangle 1 to point of rectangle 2 using scaling or translation. So, what should be scaling factor for x and y coordinates in order to transform the coordinate of rectangle 1 to rectangle 2 ? Matthew Watson If:

Slicing a circle in equal segments, Python

半城伤御伤魂 提交于 2019-12-05 08:13:43
I have a set of close of 10,000 points on the sky. They are plotted using the RA (right ascension) and DEC (declination) on the sky. When plotted, they take the shape of a circle. What I would like to do is to slice the circle into 8 equal parts and remove each part one at a time and do some calculations using the remaining parts. To do so I came up with this illustration in mind, i.e. slicing them using the arcs. I know that the equation of the arc is given by: S = r * theta where r --> radius theta --> angle (in our case 45 degrees) I would somehow like to do this like: slice1 = [] for a,b

Approximating a polygon with a circle

非 Y 不嫁゛ 提交于 2019-12-05 04:08:28
Well, approximating a circle with a polygon and Pythagoras' story may be well known. But what about the other way around? I have some polygons, that should be in fact circles. However, due to measurement errors they are not. So, what I'm looking for is the circle that best "approximates" the given polygon. In the following figure we can see two different examples. My first Ansatz was to find the maximum distance of the points to the center as well as the minimum. The circle we are looking for is maybe somewhere in between. Is there any algorithm out there for this problem? I would use scipy to

Determining if a point is inside a polyhedron

别说谁变了你拦得住时间么 提交于 2019-12-05 01:37:28
问题 I'm attempting to determine if a specific point lies inside a polyhedron. In my current implementation, the method I'm working on take the point we're looking for an array of the faces of the polyhedron (triangles in this case, but it could be other polygons later). I've been trying to work from the info found here: http://softsurfer.com/Archive/algorithm_0111/algorithm_0111.htm Below, you'll see my "inside" method. I know that the nrml/normal thing is kind of weird .. it's the result of old

Generate Non-Degenerate Point Set in 2D - C++

China☆狼群 提交于 2019-12-05 01:34:47
I want to create a large set of random point cloud in 2D plane that are non-degenerate (no 3 points in a straight line in the whole set). I have a naive solution which generates a random float pair P_new(x,y) and checks with every pair of points (P1, P2) generated till now if point (P1, P2, P) lie in same line or not. This takes O(n^2) checks for each new point added to the list making the whole complexity O(n^3) which is very slow if I want to generate more than 4000 points (takes more than 40 mins). Is there a faster way to generate these set of non-degenerate points? Instead of checking the

Find the perimeter of a subset of a near-regular grid of points

拟墨画扇 提交于 2019-12-05 01:28:48
问题 Let us consider a set of near-regular grids in 2-D. These grids are adjacent (neighbouring grids have one or more same vertices) to the neighbouring grids. Here are the sample of 10 grids with the coordinates of the vertices (longitude,latitude) are as follows A<- lon lat [,1] [,2] [1,] 85.30754 27.91250 [2,] 85.32862 27.95735 [3,] 85.34622 27.89880 [4,] 85.36732 27.94364 [5,] 85.34958 28.00202 [6,] 85.38831 27.98830 [7,] 85.38487 27.88508 [8,] 85.40598 27.92991 [9,] 85.42353 27.87134 [10,]

How do I minimise the maximum aspect ratio of two subpolygons?

旧时模样 提交于 2019-12-04 23:59:47
问题 I'd like to cut a convex polygon into two with a given ratio of areas using a straight line, such that the larger aspect ratio of the two subpolygons is minimised. My approach at the moment involves choosing a random starting point, computing the appropriate end point that splits the polygon into the target areas, then calculating the larger of the two aspect ratios. Then repeating this lots of times until I'm close enough to a minimum! The aspect ratio of a polygon A is defined as: asp(A) :=

Convex Hull and SciPy

 ̄綄美尐妖づ 提交于 2019-12-04 23:31:54
问题 I'm trying to use scipy (0.10.1) for a quick hack to visualize the convex hull. I can get the convex hull using the following code: vecs = [[-0.094218, 51.478927], [-0.09348, 51.479364], [-0.094218, 51.478927], ... [-0.094218, 51.478927], [-0.094321, 51.479918], [-0.094218, 51.478927], [-0.094222, 51.478837], [-0.094241, 51.478388], [-0.094108, 51.478116], [-0.09445, 51.480279], [-0.094256, 51.478028], [-0.094326, 51.500511]] hull = scipy.spatial.Delaunay(vecs).convex_hull the resulting array