relative coordinate or local coordinate

Asked by Leonard on 2019-08-06

Hi,
I'd like to ask that if there is relative coordinate or local coordinate so that we can generate spheres around a point/sphere whose coordinate is known. For example:
There is a sphere at (0,0,0), radius=0.5
s1=utils.sphere((0,0,0),radius=0.5)
I want to generate another sphere at the right-up-60 degrees location relative to s1 and contact to s1, for instance:
s2=utils.sphere((0,0.5,0.5*sqrt(3)),radius=0.5)
can we do this by adding the second sphere(s2) at the upper of s1 like:
s2=utils.sphere((0,0,1),radius=0.5)
and then rotate the two sphere for a certain degree (30 degree in this case)
I think it may relate to the relative coordinate or local coordinate.
Thank you in advance!

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
2019-08-11
Last query:
2019-08-11
Last reply:
2019-08-10
Best Jan Stránský (honzik) said : #1

something like this?
###
def rotateAround(point,center,axis,angle):
 d = point - center
 q = Quaternion(axis,angle)
 d = q*d
 return center + d
#
s1 = sphere((1,2,3),radius=0.5)
# center of s2 given relatively to center of s1
s2 = sphere(s1.state.pos+(0,0,1),radius=0.5)
# center of s2 is rotated
s2.state.pos = rotateAround(s2.state.pos,s1.state.pos,(1,0,0),pi/3)
print s1.state.pos
print s2.state.pos
###

cheers
Jan

Leonard (z2521899293) said : #2

Thanks Jan Stránský, that solved my question.