4
$\begingroup$

Consider these simple exampes of two overlapping lines:

RegionIntersection[Line[{{0, 0}, {2, 0}}], Line[{{1 , 0}, {2, 0}}]]
(*Line[{{1, 0}, {2, 0}}]*)
RegionIntersection[Line[{{0, 0}, {2, 0}}], Line[{{1 , 0}, {3, 0}}]]
(*Line[{{{1, 0}, {2, 0}}}]*)

In both examples Mathematica evaluates the intersection as expected. Surprisingly in the second example with extra curly brackets .

My questions: What's the reason for this behavior? How to avoid or remove the outer curly brackets?

Thanks

$\endgroup$
  • 6
    $\begingroup$ The second answer is also semantically correct, Line can represent a collection of lines. If you want to drop the extra list wrapper you can rewrite this specific case: Line[{{{1, 0}, {2, 0}}}] /. Line[{l_List}] :> Line[l] $\rightarrow$ (* Line[{{1, 0}, {2, 0}}] *). This doesn't modify the first result. $\endgroup$ – kirma May 30 at 11:14
  • $\begingroup$ @kirma Thanks for your answer! $\endgroup$ – Ulrich Neumann May 30 at 11:18
3
$\begingroup$

Turning my comment into an answer since I guess it's really a sufficient solution to the task at hand...

The second answer is also semantically correct, Line can represent a collection of lines. If you want to drop the extra list wrapper you can rewrite this specific case:

Line[{{{1, 0}, {2, 0}}}] /. Line[{l_List}] :> Line[l]

Line[{{1, 0}, {2, 0}}]

This doesn't modify the first result.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.