[gdal-dev] angle of crossing two lines
Ahmet Temiz
ahmettemiz88 at gmail.com
Tue Nov 12 03:57:36 PST 2019
Thanks a lot. It is greatly appreciated
On Tue, Nov 12, 2019 at 1:09 AM Martin Chapman <mchapman at hyperacktive.com>
wrote:
> Ahmet,
>
>
>
> The following function will return the angle in decimal degrees given 3
> points on a flat plane. The three points create the angle. If you have
> two intersecting lines then the angle of any given corner is the center
> point where the lines intersect and two end points of the lines that
> complete an angle.
>
>
>
> *// NOTE: the points must be fed to the function in clockwise order. *
>
> *// NOTE: the angle returned is an azimuth angle and not a trigonometric
> angle. Azimuth angles start with zero at north and increase clockwise
> whereas trigonometric angles zero starts to the right (east) on the x axis
> and increase going counter clockwise.*
>
>
>
> const double PI = 3.1415926535897932384626433;
>
> const double RAD2DEG = 180.0 / PI;
>
>
>
> double GetAngle(const double& x1, const double& y1, const double& x2,
> const double& y2, const double& x3, const double& y3)
>
> {
>
> double theta1 = atan2(y2 - y1, x2 - x1);
>
> double theta2 = atan2(y2 - y3, x2 - x3);
>
> double theta = (theta2 - theta1) * RAD2DEG;
>
> if (theta < 0) theta += 360.0;
>
> return theta;
>
> }
>
>
>
> *// To get the intersection of two lines use:*
>
> *// NOTE: returns FALSE if the lines don’t intersect*
>
>
>
> struct Point
>
> {
>
> double x;
>
> double y;
>
> };
>
>
>
> struct Line
>
> {
>
> Point point1;
>
> Point point2;
>
> };
>
>
>
> BOOL GetLineIntersection(const Line& line1, const Line& line2, double& x,
> double& y)
>
> {
>
> double a1 = line1.point2.y - line1.point1.y;
>
> double b1 = line1.point1.x - line1.point2.x;
>
> double c1 = a1 * line1.point1.x + b1 * line1.point1.y;
>
> double a2 = line2.point2.y - line2.point1.y;
>
> double b2 = line2.point1.x - line2.point2.x;
>
> double c2 = a2 * line2.point1.x + b2 * line2.point1.y;
>
> double determinant = a1 * b2 - a2 * b1;
>
> if (determinant == 0) return FALSE;
>
>
>
> x = (b2 * c1 - b1 * c2) / determinant;
>
> y = (a1 * c2 - a2 * c1) / determinant;
>
>
>
> return TRUE;
>
> }
>
>
>
> Best regards,
>
> Martin Chapman
>
>
>
> *From:* gdal-dev [mailto:gdal-dev-bounces at lists.osgeo.org] *On Behalf Of *Ahmet
> Temiz
> *Sent:* Monday, November 11, 2019 7:07 AM
> *To:* gdal-dev
> *Subject:* [gdal-dev] angle of crossing two lines
>
>
>
> Hi,
>
> I need to know angle of crossing two lines.
>
> which function can I use?
>
>
>
> regards
>
>
>
> --
>
> Ahmet Temiz
> Jeoloji Müh.
> Afet ve Acil Durum Yönetimi Başkanlığı
> Bilgi İşlem Dairesi Başkanlığı-CBS Grubu
>
>
> ________________________
>
> Ahmet Temiz
> Geological Eng.
> Information Systems - GIS Group
> Disaster and Emergency Management
> of Presidency
>
--
Ahmet Temiz
Jeoloji Müh.
Afet ve Acil Durum Yönetimi Başkanlığı
Bilgi İşlem Dairesi Başkanlığı-CBS Grubu
________________________
Ahmet Temiz
Geological Eng.
Information Systems - GIS Group
Disaster and Emergency Management
of Presidency
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20191112/9e069419/attachment.html>
More information about the gdal-dev
mailing list