commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luc Maisonobe <Luc.Maison...@free.fr>
Subject Re: SubLine Intersection Math 3.0
Date Tue, 14 Jun 2011 18:53:51 GMT
Hi Curtis,

Le 14/06/2011 19:38, Curtis Jensen a écrit :
> In the commons math 3.0 Geometry package, How can get the intersection
> of two SubLines?  I see that the Line class has an intersection
> method, but not the SubLine class.  I can create Lines from SubLines
> and call the intersection method, but I'm not sure how to tell if the
> resultant Vector is on the SubLines.

There is not (yet) any convenient method to get such a point. However, 
it would be interesting to add one. Feel free to open a Jira issue to 
ask for it ig you want.

In the mean time, the proper way to compute this point is as follows:

   // retrieve the underlying lines (it does not recreate them)
   Line line1 = (Line) subLine1.getHyperplane();
   Line line2 = (Line) subLine2.getHyperplane();

   // compute the intersection on infinite line
   Vector2D v2D = line1.intersection(line2);

   // check location of point with respect to first sub-line
   Location loc1 =
     sub1.getRemainingRegion().checkPoint(l1.toSubSpace(v2D));

   // check location of point with respect to second sub-line
   Location loc2 =
     sub2.getRemainingRegion().checkPoint(l2.toSubSpace(v2D));

You can the compare loc1 and loc2 as you want. If you want strict 
inclusion (i.e. without endpoints) you should simply do

   if ((loc1 == INSIDE) && (loc2 == INSIDE)) {
      return v2D;
   } else {
      return null; // or throw an exception
   }

and if you want to large inclusion (i.e. with endpoints) you should do

   if ((loc1 != OUTSIDE) && (loc2 != OUTSIDE)) {
      return v2D;
   } else {
      return null; // or throw an exception
   }

There are three possible values for Location: INSIDE, OUTSIDE and BOUNDARY.

>
> Also, How do I get the end points of the SubLine.

Here again, there is no convenience function. If you are sure you 
subline is only one segment and not several disjoints segments, you can do:

   IntervalSet is = (IntervalsSet) sub1.getRemainingRegion();
   Vector2D start = line1.toSpace(new Vector1D(is.getInf()));
   Vector2D end   = line1.toSpace(new Vector1D(is.getSup()));

If there may be several disjoint segments, use the asList method from 
IntervalSet to retrieve all segments, and perform a loop to convert the 
1D abscissa into a 2D point, using line.toSpace.

Here again, if you think it would be interesting, open a Jira issue to 
ask for a convenience function for that. In the same spirit, I guess a 
constructor with the two endpoints may be interesting.

Hope this helps
Luc

>
> Thanks,
> Curtis
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message