-1

I am trying to do this but in 3d and using a 2d circle instead of a box.

I have a line starting between the two points [ (0,0,0), (3,4,5) ] and I want to see if it intersects through

circle = Circle((2, 1), 0.5)

ax.add_patch(circle)

art3d.pathpatch_2d_to_3d(circle, z=1, zdir="x")

Is it possible to test for a path intersect on a 2d object plotted on 3d axis? From the linked example above, I want to do path.intersects_circle where I define a circle as:

I have had a look through the Bbox documentation and it seems that I can't use this method for a circle?

ttamscnal
  • 11
  • 2
  • How do you define the intersection of objects defined in different dimensions? Are you looking for an intersection of the projection? I'm afraid your question is not well posed. – David Zwicker May 24 '13 at 13:44
  • In the example I linked, from my understanding, if a line passed through the `Bbox` then this changes the colour of the line. I'm looking to change the colour of the line, and also keep a log of the number of lines that pass through the circle. I don't specifically need to know the x,y,z of where it passed through the circle. Hope that makes a bit more sense? – ttamscnal May 24 '13 at 14:06
  • That is downstream of the problem I describe. Conceptually, I don't understand what it means when a 2d object intersects a 3d object. That doesn't make any sense to me, since both objects are defined in different spaces. – David Zwicker May 24 '13 at 14:44
  • Sorry, I have tried to post an image of the graph I have, but I can't post as I don't have enough posts to allow me to do this. If you were to plot just one the circles here, that is what I am calling my 2d object. Changed wording in question to hopefully be more clear. – ttamscnal May 24 '13 at 16:07
  • If I understand your comment correctly, you are looking for the intersection of a 2d object (the circle) with the *projection* of a 3d object. I don't think there is anything built into mpl to achieve that. After all, mpl is more focused on 2d plotting. – David Zwicker May 24 '13 at 16:14
  • Ok, looks like I will have to manually try and do this. Thank you for your patience. – ttamscnal May 24 '13 at 16:25

1 Answers1

1

This sounds more like an algebraic problem than related to matplotlib.
This is how I understand your question:

  • you have a circle at (x=2,y=1) with a radius of r=0.5
  • this circle is located in a plane at a constant z=1

1.) You need to determine where your vector pierces the plane which is parallel to the x,y-plane and at z=1. For the vector you specify in your question this intersection is at:

x = 3./(2.**0.5)
y = 4./(2.**0.5)
z = 1.

2.) You need to determine if this intersection falls into the part of the plane covered by the circle. The maximum y-coordinate your circle reaches is 1.5 - the y-coordinate of the intersection is already larger. Hence your straight line does not pierce the circle.

All this being said, I would recommend implementing an algebraic check based on the intersection with the plane and determining if this intersection is part of the circle. And only then using matplotlib.

Schorsch
  • 7,761
  • 6
  • 39
  • 65