answerstu

geometry - Determine angle of triangle

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

geometry - Finding the intersection(s) between two angle ranges / segments

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

geometry - How do I compute a python function which calculates/plot minimum distance between a point and a curve?

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

geometry - 2D orientation test barycentric coordinates

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

geometry - Find all polygons formed by intersections of lines

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

geometry - Calculate signed distance between point and rectangle

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

geometry - Direction of angle after reflection

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

geometry - How to update a feature in an Openlayers.Layer?

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

geometry - Nearest neighbor on a unit sphere, with roughly evenly distributed points

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

geometry - Point of intersection between 4 points

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

vertices - Geometry from Scenekit primitives

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

geometry - How can I make a directed arc of a circle (or a directed curve)?

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

geometry - Least square straight line intersection

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