Given following problem:I have 2 solutions:First is to calculate difference in absolute angles, then renormalize angle. bad idea, 2 x atan2() is slow, renormalisation is inefficient.angle = clamp_to_range( atan2(P1.y, P1.x) - atan2(P0.y, P0.x));Second is to calculate dot product, normalize, calculate arccos(). Also bad idea, because angle sign will be incorrect.angle = acos( dot(P0, P1) / sqrt( dot(P0,P0) * dot(P1, P1) ) );I feel, that there should be some formula. How to solve given problem efficiently?...Read more

We have two angle ranges, (aStart, aSweep) and (bStart, bSweep), where the start is the place of the start of the angle segment in the range [0, 2π), and sweep is the size of the segment, in the range (0, 2π].We want to find all of the angle ranges where these two angle ranges overlap, if there are any.We need a solution that covers at least three kinds of situations:But the number of cases increases as we confront the reality of the Devil Line that exists at angle = 0, which messes up all of the inequalities whenever either of the angle ranges...Read more

How can I tell whether a circle and a rectangle intersect in 2D Euclidean space? (i.e. classic 2D geometry)...Read more

import numpy as npimport matplotlib.pyplot as pltfrom scipy.optimize import fmin_cobylaP = (2487,1858) def f(x): return (1.77425666496e-05 * x**3 + -0.125555135823 * x**2 + 296.656015233 * x + -232082.382985)def objective(X): x,y = X return np.sqrt((x - P[0])**2 + (y - P[1])**2)def c1(X): x,y = X return f(x) - yX = fmin_cobyla(objective, x0=[0.1, 0.01], cons=[c1])print ("The minimum distance is {0:1.2f}".format(objective(X)))v1 = np.array(P) - np.array(X)v2 = np.array([1, 2.0 * X[0]])print ("dot(v1, v2) = ",np.dot(v1, v2))x =...Read more

If I have an ordered 3-tuple of points in integer barycentric coordinates,how do I test orientation on them?(I want to know if the points are collinear, form a left turn or a right turn)The "algorithm" has to be quite robust so I don't want to convert the coordinates to cartesians.For cartesians, there is a very nice way to determine this using only multiplication and addition:https://www.cs.cmu.edu/~quake/robust.htmlThere is a similar way to find out if three points are collinear here,but I don't know if I can use it for this application:http:...Read more

I have a maze described by walls as line segments (no given order). Given a point, I need to determine whether its inside the maze or no. Everything is in the Cartezian plane(no discretization).My idea is to transform the problem as follows:Given some line segments in the plane, find all polygons with vertices in the endpoints of the given segments and with sides lying on the segments (you can see in the image below that you can't assume the sides will form a subset of segments).And then just check: if a point is only inside one polygon, then i...Read more

I'm trying to write a function in GLSL that returns the signed distance to a rectangle. The rectangle is axis-aligned. I feel a bit stuck; I just can't wrap my head around what I need to do to make it work.The best I came up with is this:float sdAxisAlignedRect(vec2 uv, vec2 tl, vec2 br){ // signed distances for x and y. these work fine. float dx = max(tl.x - uv.x, uv.x - br.x); float dy = max(tl.y - uv.y, uv.y - br.y); dx = max(0.,dx); dy = max(0.,dy); return sqrt(dx*dx+dy*dy);}Which produces a rectangle that looks like:The l...Read more

Say if I had a triangle and I was to draw a line towards one of the sides of the triangle, how would I create the reflected line of when that line hits the side of the triangle in Maple. I just drew this quickly in paints (and so its not accurately). Is there a way to do this in maple. ThanksI currently have,with(plots):with(plottools):a:=polygon([[0,0],[2,0],[1,2]]):b:=polygon([[2,0],[4,0],[3,2]]):e:=line([2.5,2],[2.5,1]):f:=line([2.5,1],[1.72,0.484]):display(a,b,e,f);...Read more

i have an xml file with coordinates in it and i want to draw a line of those points on an Openlayers Map. I already have a Openlayers.Layer.Vector and i am creating a feature as follows:var points = [];for (var i = 0; i < coords.length; i++){ point = new OpenLayers.Geometry.Point(aPointsArray[i].lon, aPointsArray[i].lat); points.push(point);}var geometry = new OpenLayers.Geometry.LineString(points);var feature = new OpenLayers.Feature.Vector(geometry, null,{ strokeColor: aColor, strokeOpacity: 0.7, strokeWidth: 3});aLayer.addF...Read more

I'm writing a program that implements SCVT (Spherical Centroidal Voronoi Tesselation). I start with a set of points distributed over the unit sphere (I have an option for random points or an equal-area spiral). There will be from a several hundred to maybe 64K points.I then need to produce probably several million random sample points, for each sample find the nearest point in the set, and use that to calculate a "weight" for that point. (This weigh may have to be looked up from another spherical set, but that set will stay static for any gi...Read more

I have a game represented like this :I would like to calculate the coordinates of the point x4,y4.What I know is : y4 = y3, x4 is on the line x1,y1,x2,y2 and the line is 45° (degree)I tried x4 = y4 - y1 + x1 but it doesn't work very well..Any ideas ?...Read more

I have 4 points. If I were to draw lines from every point to every other point, I will get 4 exterior lines and 2 lines crossing in the middle. What I'm trying to identify is the point at which the 2 crossing lines intersect. All I know is the coordinates of each of the 4 points (x0, y0, x1, y1, x2, y2, x3, y3).Is there a simple solution to this that I'm missing?Edit: Edit: Fixed. I was missing the two formulas: x = x1 + ua (x2 - x1) andy = y1 + ua (y2 - y1)....Read more

I am successfully extracting vector data from SceneKit primitives, very much along the lines as in the question/answer here:Extracting vertices from scenekitThis does not seem to work for all the geometries SceneKit generates though. I can extract the standard box, sphere etc, but special features like chamfer or more complex geometries (e.g. from SCNText) simply don't seem to be contained in the standard SceneKit geometry. Also: The normal SCNBox and SCNSphere only come in one geometry resolution and don't respect the parameters provided (e.g....Read more

I'd like to display a directed circular arc in Mathematica, using something as simple as Arrow. The best I have been able to come up with is this example that nails an Arrow onto one end of a circular arc. But I suspect there is a more direct way to achieve the same effect.start=\[Pi];Manipulate[Graphics[{ Arrow[{{Cos[\[Theta] + If[\[Theta] < start, .01, -.01]], Sin[\[Theta] + If[\[Theta] < start, .01, -.01]]}, {Cos[\[Theta]], Sin[\[Theta]]}}], Circle[{0, 0}, 1, {start, \[Theta]}]},PlotRange -> 2], {{\[Theta], ...Read more

I have 2 cluster of points, each of which are derived from a RANSAC line fitting (among several points in the set). Solving the system of equations, I can retrieve the parameters for the two lines in least square fashion. I want to determine if these two lines intersect within the set of points or not. If so, I want to determine the intersection point.I guess I need to do some kind of approximation for estimating the intersection (because unless they are parallel, they will intersect at some point, but I want to determine if that point belongs...Read more