Context: I'm trying to clip a topographic map into the minimum-size ellipse around a number of wind turbines, to minimize the size of the map. The program doing this map clipping can clip in ellipses, but only ellipses with axes aligned along the x and y axes.
I know the algorithm for the bounding ellipse problem (finding the smallest-area ellipse that encloses a set of points).
But how do I constrain this algorithm (or make a different algorithm) such that the resulting ellipse is required to have its major axis oriented either horizontally or vertically, whichever gives the smallest ellipse -- and never at an angle?
Of course, this constraint makes the resulting ellipse larger than it "needs" to be to enclose all the points, but that's the constraint nonetheless.
The algorithm described here (referenced in the link you provided) is about solving the following optimization problem:
minimize log(det(A))
s.t. (P_i - c)'*A*(P_i - c)<= 1
One can extend this system of inequalities with the following constraint (V is the ellipse rotation matrix, for detailed info refer the link above):
V == [[1, 0], [0, 1]] // horizontal ellipse
or
V == [[0, -1], [1, 0]] // vertical ellipse
Solving the optimization problem with either of these constraints and calculating the square of the resulting ellipses will give you the required result.
Related
I’m new to three (and, in a way, to 3d in general…) and I need to do something that appear to be way more complicated than I thought… I have two needs :
Draw a polygon from a set of points
Extrude that polygon
As an input, I have a set of points in 3d (x, y and z) defining the outline of the polygon and the “depth” of the extrusion. Each point can be anywhere in x/y/z, all aligned on a “plane” (that plane being rotated/moved in space by unknown values beforehand).
I thought it would be relatively easy to create this polygon “in the air” and extrude it in the directions of the polygon’s normals, but I can’t find out how to do it.
As an example, this is a (simple) possible input for my use case. Note that I can have more than 3 points :
var polygon = {
"points":[
[0, 0, 0],
[0, 10, 10],
[10, 0, 10]
],
"extrude":5
}
As I understand it, Three can only create 2d polygons. I thought of “triangulating” my points from their final 3d position to a 2d plane (and then rotate this “plane” so the points go back to their original position), but I’m not quite sure how to do that and I fear that rounding errors might move my points a bit… Is there a better way? Can someone push me in the right direction?
Given a 3D object, how do I convert it into an approximated shape in which all the sides of the object are parallel to either of the co-ordinate planes, and all the vertices have integer co-ordinates?
For example, a sphere with center at origin and a radius of 1.5 will be approximated to a cube with center at origin and side length of 2.
For another example, the line given by x = y = 0.5 will have an approximated shape as a rectangular parallelepiped with infinite length, and width and breadth as 1, and positioned such that one of its edge is along z-axis, while all the faces are along or parallel to either of x-z or y-z co-ordinate planes.
I am working with finite objects only, the above example is only meant to explain my needs.
I want an algorithm which can do this for me for any shape.
In general case you need to determine maximum and minimum shape coordinates along every axis and define minimum axis aligned integer bounding box with values rounded to larger (using Ceil) for max and rounded to smaller (using Floor) for min coordinates. For example:
XMin_Box = Floor(XMin_Shape)
XMax_Box = Ceil(XMax_Shape)
Edit:
If you need to approximate a shape with more precision, consider some kind of voxelization (3d analog of 2d rasterization)
I am having trouble figuring out the math for a problem I am having.
I have an n by m rectangle and need to place k points in it such that points are, as close as possible, completely equidistant from each other.
Normally this is pretty easy, I construct the regular polygon with k points on it, center it in the center of my rectangle, stretch it to fit and voila, its vertices are my output points.
The catch is that when calculating distances on this rectangle, you can wrap. As such the point (0,0) is just 1 pixel away from the point (n-1,m-1) (using 0-indexed coordinates).
I've been messing around a bit on paper and getting nowhere fast with this. Does anybody have any idea how to calculate this?
tl;dr:
Inputs: n - width of rectangle, m - height of rectangle, k - number of points
Outputs: k pairs of (x,y) coordinates
Constraints: the output coordinates are equidistant from one another under wrapping coordinate systems.
Any advice on where I could look for such a geometry problem?
I have an image of a 3D rectangle (which due to the projection distortion is not a rectangle in the image). I know the all world and image coordinates of all corners of this rectangle.
What I need is to determine the world coordinate of a point in the image inside this rectangle. To do that I need to compute a transformation to unproject that rectangle to a 2D rectangle.
How can I compute that transform?
Thanks in advance
This is a special case of finding mappings between quadrilaterals that preserve straight lines. These are generally called homographic transforms. Here, one of the quads is a rectangle, so this is a popular special case. You can google these terms ("quad to quad", etc) to find explanations and code, but here are some sites for you.
Perspective Transform Estimation
a gaming forum discussion
extracting a quadrilateral image to a rectangle
Projective Warping & Mapping
ProjectiveMappings for ImageWarping by Paul Heckbert.
The math isn't particularly pleasant, but it isn't that hard either. You can also find some code from one of the above links.
If I understand you correctly, you have a 2D point in the projection of the rectangle, and you know the 3D (world) and 2D (image) coordinates of all four corners of the rectangle. The goal is to find the 3D coordinates of the unique point on the interior of the (3D, world) rectangle which projects to the given point.
(Do steps 1-3 below for both the 3D (world) coordinates, and the 2D (image) coordinates of the rectangle.)
Identify (any) one corner of the rectangle as its "origin", and call it "A", which we will treat as a vector.
Label the other vertices B, C, D, in order, so that C is diagonally opposite A.
Calculate the vectors v=AB and w=AD. These form nice local coordinates for points in the rectangle. Points in the rectangle will be of the form A+rv+sw, where r, s, are real numbers in the range [0,1]. This fact is true in world coordinates and in image coordinates. In world coordinates, v and w are orthogonal, but in image coordinates, they are not. That's ok.
Working in image coordinates, from the point (x,y) in the image of your rectangle, calculate the values of r and s. This can be done by linear algebra on the vector equations (x,y) = A+rv+sw, where only r and s are unknown. It will boil down to a 2x2 matrix equation, which you can solve generally in code using Cramer's rule. (This step will break if the determinant of the required matrix is zero. This corresponds to the case where the rectangle is seen edge-on. The solution isn't unique in that case. If that's possible, make special exception.)
Using the values of r and s from 4, compute A+rv+sw using the vectors A, v, w, for world coordinates. That's the world point on the rectangle.
I'm looking for skew algorithm, just like on photoshop, edit->transform->skew
is there any simple matrix which could do that?
what I've seen so far was basic skew matrix (shear) but its lack of control point, doesn't like on photoshop which have at least 4 points on each corner of rectangle and we can move each control point freely.
I need to implement it to transform a plane.
Looking at http://www.w3.org/TR/SVG11/coords.html, which talks about SVG, it says:
A skew transformation along the x-axis is equivalent to the matrix
or [1 0 tan(a) 1 0 0], which has the effect of skewing X coordinates by angle a.
A skew transformation along the y-axis is equivalent to the matrix
or [1 tan(a) 0 1 0 0], which has the effect of skewing Y coordinates by angle a.
Hope that helps! :)