Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question/Feature request - 3d circle #19865

Open
Stinosko opened this issue Jul 31, 2020 · 8 comments
Open

Question/Feature request - 3d circle #19865

Stinosko opened this issue Jul 31, 2020 · 8 comments

Comments

@Stinosko
Copy link

Hey,

I'm wondering if the library has a way to use 3 dimensional circles? I have a program that spit out 3d circles by providing the centerpoint, radius and normal vector of the circle his plane. I want to calculate the intersection of a line in the same plane with the circle, is that possible?

@sylee957
Copy link
Member

I think that we should support more wider varieties of geometric primitives
But problem is that that there are multiple ways to draw plane circles in 3D space regarding how it is tilted, so there should be a good way to describe such rotation

@Stinosko
Copy link
Author

What do you mean? If you provide a normal, center point and radius than you can only draw one circle as far as i can think off? It might be more tricky for a ellipse as his rotation does matter.

Correct me if I'm wrong!

@sylee957
Copy link
Member

No, I mean about how the plane where the circle is drawn is tilted

@sylee957
Copy link
Member

Okay, I see you have mentioned to use normal vector

@sylee957
Copy link
Member

I’d tell you that I missed your detail of using normal vectors

@oscarbenjamin
Copy link
Contributor

It is possible to do this if you give equations for the circle and line. The equations for the circle are something like:

( r - c ) . n = 0  # circle is in the plane
| r - c |^2 = R^2

where r is the arbitrary position vector, c the centre, n the normal and R the radius. The equation for the line will be something like

r = a + t b

where t is the parameter of the line.

Using the vector module we have:

In [24]: from sympy.vector import CoordSys3D                                                                                      

In [25]: N = CoordSys3D('N')                                                                                                      

In [26]: x, y, z = N.base_scalars()                                                                                               

In [27]: i, j, k = N.base_vectors()                                                                                               

In [28]: c = 1*i                                                                                                                  

In [29]: n = i + j                                                                                                                

In [30]: R = 2                                                                                                                    

In [31]: a = c                                                                                                                    

In [32]: b = i - j                                                                                                                

In [33]: t = Symbol('t')                                                                                                          

In [34]: r = a + t*b                                                                                                              

In [35]: r                                                                                                                        
Out[35]: (t + 1) i_N + (-t) j_N

In [36]: (r - c).dot(n)                                                                                                           
Out[36]: 0

In [37]: r - c                                                                                                                    
Out[37]: (t) i_N + (-t) j_N

In [42]: (r - c).dot(r - c)                                                                                                       
Out[42]: 
   2
2t 

In [43]: solve((r - c).dot(r - c) - R**2, t)                                                                                      
Out[43]: [-√2, 2]

In [44]: r                                                                                                                        
Out[44]: (t + 1) i_N + (-t) j_N

In [45]: sol = solve((r - c).dot(r - c) - R**2, t, dict=True)                                                                     

In [46]: sol                                                                                                                      
Out[46]: [{t: -√2}, {t: 2}]

In [47]: [r.subs(s) for s in sol]                                                                                                 
Out[47]: [(1 - 2) i_N + (2) j_N, (1 + 2) i_N + (-√2) j_N]

@Stinosko
Copy link
Author

Oooh, that comment wasn't present when sending mine comment @sylee957
I'll remove it!

@Stinosko
Copy link
Author

@oscarbenjamin I'll give it a try, thank you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants