GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Math::Intersection::StraightLine(3) User Contributed Perl Documentation Math::Intersection::StraightLine(3)

Math::Intersection::StraightLine - Calculate intersection point for two lines

version 0.05

  use Math::Intersection::StraightLine;
  use Data::Dumper;
  my $finder = Math::Intersection::StraightLine->new();

  # one intersection point
  my $vector_a = [[20,60],[-40,0]];
  my $vector_b = [[50,80],[0,50]];
  my $result = $finder->vectors($vector_a,$vector_b);
  print Dumper($result);

  # no intersection point
  my $point_a = [[20,60],[30,10]];
  my $point_b = [[50,80],[50,75]];
  $result = $finder->point_limited($point_a,$point_b);
  print Dumper($result);

This module calculates the intersection point of two straight lines (if one exists). It returns 0, if no intersection point exists. If the lines have an intersection point, the coordinates of the point are the returnvalue. If the given lines have infinite intersection points, -1 is returned. Math::Intersection::StraightLine can handle four types of input:

Often straight lines are given in functions of that sort: y = 9x + 3

the vector assignment of the line

  (10)     +     lambda(30)
  (20)                 (50)

The straight lines are described with two vectors to points on the line

  X1 = (10)             X2 = (40)
       (20)                  (70)

If the module should test, if an intersection point of two parts exists

  X1 = (10)             X2 = (40)
       (20)                  (70)

The following example should clarify the difference between "points" and "point_limited":

  $line_a = [[20,60],[30,10]];
  $line_b = [[50,80],[50,75]];
  $result = $finder->points($line_a,$line_b);

  $line_a_part = [[20,60],[30,10]];
  $line_b_part = [[50,80],[50,75]];
  $result = $finder->point_limited($line_a_part,$line_b_part);

The first example returns the intersection point 50/-90, the second returns 0 because $line_a_part is just a part of $line_a and has no intersection point with the part of line b.

In the first example, the lines are changed to the vectors of the lines.

  $vector_a = [[20,60],[30,10]];
  $vector_b = [[50,80],[60,30]];
  $result = $finder->point_limited($vector_a,$vector_b);
  ok($result == 0,'parallel lines(diagonal)');

  $vector_a = [[20,60],[20,10]];
  $vector_b = [[60,80],[20,10]];
  $result = $finder->vectors($vector_a,$vector_b);
  ok($result == -1,'overlapping vectors');

  $vector_a = [[20,60],[30,10]];
  $vector_b = [[50,80],[50,75]];
  $result = $finder->points($vector_a,$vector_b);
  ok($result->[0] == 50 && $result->[1] == -90,'Lines with one intersection point');

  # test y=9x+5 and y=-3x-2
  my $function_one = [9,5];
  my $function_two = [-3,-2];
  $result = $finder->functions($function_one,$function_two);

Note! The coordinates for the intersection point can be imprecise!

  # test y=9x+5 and y=-3x-2
  my $function_one = [9,5];
  my $function_two = [-3,-2];
  $result = $finder->functions($function_one,$function_two);

returns

  $VAR1 = [
          '-0.583333333333333', # this is imprecise
          '-0.25'
          ];

returns a new object of "Math::Intersection::StraightLine"

Renee Baecker <reneeb@cpan.org>

This software is Copyright (c) 2015 by Renee Baecker.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)
2015-02-25 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.