Will
Will

Reputation: 1933

Get subpath in Raphael.js between two points, not positions

I have a path in Raphael.js which is a bezier curve. Two lines intersect this path. I can get the points of the intersections with Raphael.pathIntersection(). I want to get the path string for the subpath between these two points, though. Raphael.getSubPath() needs to know the positions along the path, but I don't know these positions, just the absolute points. How can I go about getting the positions of these intersections so I can find the subpath?

Thanks

Edit: below is the intersection object that is returned for the first of the two intersections that make up the start and finish of the subpath I want to find. I can see from this which segment the intersection occurs in, but how to get the actual position along the path from its start from this information?

0: Object
  bez1: Array[8]
    0: 746.6695658365885
    1: 444.9913024902344
    2: 746.6695658365885
    3: 444.9913024902344
    4: 767.3333333333334
    5: 383
    6: 767.3333333333334
    7: 383
  bez2: Array[8]
    0: 743
    1: 427
    2: 750
    3: 428.5
    4: 752.5
    5: 428.8333333333333
    6: 761
    7: 432
  segment1: 1
  segment2: 9
  t1: 0.330626006717131
  t2: 0.5304347826090153
  x: 751.9768115942079
  y: 429.0695652173915

Upvotes: 2

Views: 1389

Answers (2)

incognito
incognito

Reputation: 53

Sorry that I guess I can't understand english, so in the following case:

       _|_________
       \|
        |\
        | \
        |  \
 _______|___\
        |

(can't post figure here, hope you understand) with Raphael.pathIntersection(), it would return something similar to this:

0: Object
    bez1: Array[8]
    bez2: Array[8]
    segment1: 1
    segment2: 1
    t1: 0.49131376884437716
    t2: 4.686749827219845e-13
    x: 221.6492901831065
    y: 425.40404348103067
    __proto__: Object
1: Object
    bez1: Array[8]
    bez2: Array[8]
    segment1: 2
    segment2: 1
    t1: 0.9999999999901484
    t2: 1
    x: 281.50000000000495
    y: 325.3666666666513
    __proto__: Object
2: Object
    bez1: Array[8]
    bez2: Array[8]
    segment1: 3
    segment2: 1
    t1: 5.420619967753905e-13
    t2: 0.9999999999989502
    x: 281.49999999999204
    y: 325.3666666666728
    __proto__: Object
    length: 3
__proto__: Array[0]

subpath of every intersecting segment can be obtained by subpath on these segment one by one, with Raphael.getTotalLength and Raphael.getSubpath

        |
        |
        |
        | 
        |  
        |___
        |

        |
       \|
        |\
        | \
        |  \
        |   \
        |

       _|
        |
        |
        | 
        |  
        |   
        |

and them join these subpath into one to get the final path?

       _|
       \|
        |\
        | \
        |  \
        |___\
        |

Upvotes: 1

Amit Aviv
Amit Aviv

Reputation: 1816

Actually pathIntersection also returns the positions on the intersecting paths as t1 & t2 in the return object, not only the absolute position.

Upvotes: 2

Related Questions