Area of polygon using c++? [closed] - c++

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
How can i calculate the area of a polygon in c++ only by knowing the x and y coordonates of the points which make the polygon?

A simple google search shows the answer provided that you are dealing with non-self-intersecting polygons. The sign of the area is positive if the points on the polygon are arranged in counterclockwise order. This formula does not assume that the polygon is convex.
http://mathworld.wolfram.com/PolygonArea.html
Here, the area is found by summing the determinent of neighboring points. Each determinent computes the area of the parallelogram formed by the vector e.g. (x1,y1) and (x2,y2) (where both vectors stem from the origin (0,0)). The division by 2 gives the area of a triangle. When traveling around the polygon, the triangles will have a positive area if your polygon is convex. Otherwise, negative areas of these triangles will cancel with their positive counterparts for the case of a concave polygon giving you the correct result.

Simple wikipedia search shows the answer:
http://en.wikipedia.org/wiki/Polygon#Area_and_centroid

Related

Find the boundary of a polygon (or a staircase) c++ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I'm doing an 2D bin packing algorithm. The goal is to put a set of rectangle into a bin one by one.
At each rectangle insertion, i want to update the boundary between occupied area and free area. Thus, i'm looking for an algorithm or the way to do it. Algorithm must be able to:
1) Find the boundary after rectangle insertion (or find all points of the boundary).
2) Travel clockwise all the points of the boundary (imagine that now I have all points coordinates of the boundary).
3) At each corner (point) of the boundary, the algorithm can determinate if this point is on the top left, top right, bottom left, bottom right
Any help would be greatly appreciated. If you need more information, just ask and I'll provide all I can.
Thank you
See these links:
http://en.wikipedia.org/wiki/Bin_packing_problem
How is 2D bin packing achieved programmatically?
https://math.stackexchange.com/questions/352575/2d-bin-packing-problem-with-opportunity-to-optimize-the-size-of-the-bin

Interpolation of Matrix in C++ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
May I know how can I do the interpolation for a matrix in C++?
Eg:
I have a 3x3 matrix
{0 0 0
0 1 1
0 0 1}
I wish to resize it to a 10x10 matrix using bilinear interpolation.
Any tips or references about this?
What you want to do is called image resizing using bilinear interpolation. Knowing that google is your friend. I would try using a C++ library for that purpose. This question covers all C++ imaging libraries: Fastest C/C++ image resizing library Any reasonable library should satisfy your needs.
In order to linearly interpolate between two things you need to embed (put) them in a common vector space and then "draw" the line between them.
I can't see a useful embedding of a 3x3 matrix and a 10x10 matrix in a common vector space...

Area of intersecting triangles [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to solve a question, but it's a little hard and I need some help. The question is:
we have 2 triangles, and we have the coordinates of the vertices like (x1, y1), (x2, y2), (x3, y3), (a1, b1), (a2, b2), (a3, b3).
We want to measure the area that two triangles are on each other. It may be 0 or more.
For example, if we have for first triangle (0,0) (3,0) (0,3) and the second (0,0) (3,3) (3,0), the common area will be 2.25.
How should i write a program to solve this?
The problem of intersecting triangles (and convex polygon in general) is way tougher than it seems, especially if you wanna solve it in linear time with respect to the number of edges involved.
You can consider this page to have an idea of a working algorithm for general convex polygons (the algorithm is based on rotating calipers. Indeed, there's some abstract geometry behind, in particular, the geometric Hanh-Banach theorem).
Consider that once you have the intersection polygon, which is convex, evaluating the area is trivial.
Thus, you have two options:
You keep the problem abstract (somehow you consider triangles as convex polygons, and that's it) and a fast solution in C/C++ can be achieved through the GPC library (which is written in C) or, alternatively, for instance, through boost::geometry.
You specialize just for triangles: in this case, my advice is to consider this wonderful paper which details topologically the possible ways of intersecting involved, and gives an efficient implementation of the solution.
I have one more thing to say: when you consider your problem with toy triangles (i.e. low skewness, sizes way larger than machine precision) you can still think to implement your own algorithm and play with it. But, when you have to intersect millions of possibly ill-conditioned triangles per second, you'd better rely on a good and fast library.

Histogram equalization implementation [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
All resources that I have found a very different and I am not sure what I have to do.
Now I already got my histogram which was pretty straight forward, I also got my cumulative histogram
I don't know how I have to use this new histogram to get a better contrast in my image. It is a image from 0 to 255 -> black to white (Pseudo code would be enough)
I am not able to make this connection on my own.
ps: It's about the general idea.
High contrast images have gaps (zeros or near zeros), that appear on "left" and "right" (high and low) sides of histogram. Reduction of contrast can be achieved by remapping lightness values to a wider range.
Lets say on a histogram you have all values filled with 0 up until index=35 (histogram[35]) and then all 0 after index=200 (histogram[200]). Remapping of 35 to 0, and 200 to 255 and interpolation everything in between accordingly will reduce total image contrast.
To increase contrast, a reverse of the above should be applied, so that the histogram is "compressed" from low and high ends.

COUNTING number of pairs of intersecting chords [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Consider N chords in a circle, each determined by its endpoints. Describe an O(nlogn) solution for determining the number of pairs of chords that intersect inside the circle.
ASSUMPTION: No two chords share an endpoint.
There exists a general line-segment intersection algorithm which does the job in O(nlogn).
This can be used in your case as two chords can't intersect in the exterior of a circle.
The following link contains the algorithm:
http://www.cs.princeton.edu/~chazelle/pubs/IntersectLineSegments.pdf
P.S.
It requires knowledge of basic computational geometry (line sweeps, range trees).
Hope this helps.
Off the top of my head, sort the chord endpoints by polar angle (this is the O(n log n) part). Then read through the sorted list (which is O(n)) - if two adjacent endpoints belong to the same chord, it has no intersections. Where two adjacent entries in the list belong to different chords, there may be an intersection depending on where the other endpoints for those two chords lie - e.g. if a chord A has endpoints A1 and A2 in their sorted order, and similarly chord B has B1 and B2, finding B2-A1 in the list is not an intersection, because B1 is earlier and A2 is later. However, B1-A2 would be an intersection.
See also biziclop's comment for another, somewhat more carefully constructed, solution.