da timetable57 » 22 apr 2014, 13:39
strawberryfield ha scritto:timetable57 ha scritto:Grazie Roby, attendo con calma (non è vero)
La calma è la virtù dei forti
da strawberryfield » 28 apr 2014, 21:39
da strawberryfield » 28 set 2014, 17:05
da timetable57 » 28 set 2014, 20:15
da strawberryfield » 7 nov 2014, 23:32
da timetable57 » 8 nov 2014, 18:10
da timetable57 » 8 nov 2014, 20:00
da strawberryfield » 8 nov 2014, 22:00
da strawberryfield » 15 nov 2014, 9:42
da timetable57 » 15 nov 2014, 15:34
da strawberryfield » 19 nov 2014, 22:20
timetable57 ha scritto:Non ne capisco un acca ma penso sia una buona cosa
Codice: Seleziona tutto
// COPYRIGHT (c) 2014 Roberto Ceccarelli - CASASOFT
// http://strawberryfield.altervista.org
//
// CASASOFT polyTestClass
//
// CASASOFT polyTestClass is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// CASASOFT polyTestClass is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with CASASOFT polyTestClass. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using casasoft.utmClass;
namespace casasoft.polyTestClass
{
/// <summary>
/// Utilities to check points against a polygon
/// </summary>
[System.Runtime.CompilerServices.CompilerGenerated]
class NamespaceDoc
{
}
/// <summary>
/// Utility to check points against a polygon
/// </summary>
/// <remarks>
/// The solution is to compare each side of the polygon to the Y (vertical) coordinate of the test point,
/// and compile a list of nodes, where each node is a point where one side crosses the Y threshold of the test point.
/// In this example, eight sides of the polygon cross the Y threshold, while the other six sides do not.
/// Then, if there are an odd number of nodes on each side of the test point, then it is inside the polygon;
/// if there are an even number of nodes on each side of the test point, then it is outside the polygon.
/// In our example, there are five nodes to the left of the test point, and three nodes to the right.
/// Since five and three are odd numbers, our test point is inside the polygon.
///
///(Note: This algorithm does not care whether the polygon is traced in clockwise or counterclockwise fashion.)
///
/// From http://alienryderflex.com/polygon
/// </remarks>
public class polyTest
{
/// <summary>
/// Polygon vertices list
/// </summary>
protected List<UTMclass.xy> poly = null;
/// <summary>
/// Constructor
/// </summary>
public polyTest()
{
poly = new List<UTMclass.xy>();
}
/// <summary>
/// Set polygon from a list of <see cref="UTMclass.xy"/> class
/// </summary>
/// <param name="polyList">Vertex list as <see cref="UTMclass.xy"/> class</param>
public polyTest(List<UTMclass.xy> polyList)
{
poly = polyList;
precalculate();
}
/// <summary>
/// Insert a vertex of the poly
/// </summary>
/// <param name="vertex">Vertex coords as <see cref="UTMclass.xy"/> class</param>
public void addVertex(UTMclass.xy vertex)
{
poly.Add(vertex);
}
/// <summary>
/// how many corners the polygon has
/// </summary>
protected int polySides;
/// <summary>
/// storage for precalculated constants
/// </summary>
private Double[] constant;
/// <summary>
/// storage for precalculated multipliers
/// </summary>
private Double[] multiple;
/// <summary>
/// Call to initialize the constant[] and multiple[] arrays
/// </summary>
/// <remarks>
/// pre-calcuation efficiency improvement provided by Patrick Mullen.
/// This is useful if you have many points that need to be tested against the same (static) polygon
/// </remarks>
public void precalculate()
{
polySides = poly.Count;
constant = new Double[polySides];
multiple = new Double[polySides];
int j = polySides - 1;
for (int i = 0; i < polySides; i++)
{
if (poly[j].y == poly[i].y)
{
constant[i] = poly[i].x;
multiple[i] = 0;
}
else
{
constant[i] = poly[i].x - (poly[i].y * poly[j].x) / (poly[j].y - poly[i].y) + (poly[i].y * poly[i].x) / (poly[j].y - poly[i].y);
multiple[i] = (poly[j].x - poly[i].x) / (poly[j].y - poly[i].y);
}
j = i;
}
}
/// <summary>
/// Check if a point is inside the polygon
/// </summary>
/// <param name="point">Point coords as <see cref="UTMclass.xy"/> class</param>
/// <returns>True if the point is inside the polygon</returns>
/// <remarks>
/// The function will return YES if the point x,y is inside the polygon, or
/// NO if it is not. If the point is exactly on the edge of the polygon,
/// then the function may return YES or NO.
///
/// Note that division by zero is avoided because the division is protected
/// by the "if" clause which surrounds it.
/// </remarks>
public Boolean testPoint(UTMclass.xy point)
{
Boolean ret = false;
int j = polySides - 1;
for (int i = 0; i < polySides; i++)
{
if ((poly[i].y < point.y && poly[j].y >= point.y
|| poly[j].y < point.y && poly[i].y >= point.y))
{
ret ^= (point.y * multiple[i] + constant[i] < point.x);
}
j = i;
}
return ret;
}
}
}
da timetable57 » 19 nov 2014, 22:54
da strawberryfield » 23 nov 2014, 21:22
timetable57 ha scritto:Non so perché ma confido...confido...