Plotting a point on the edge of a sphere

后端 未结 2 961
名媛妹妹
名媛妹妹 2020-11-30 04:59

So coming from a flash background I have an OK understanding of some simple 2D trig. In 2d with I circle, I know the math to place an item on the edge given an angle and a

相关标签:
2条回答
  • 2020-11-30 05:25

    Your position in 3d is given by two angles (+ radius, which in your case is constant)

    x = r * cos(s) * sin(t)
    y = r * sin(s) * sin(t)
    z = r * cos(t)
    

    here, s is the angle around the z-axis, and t is the height angle, measured 'down' from the z-axis.

    The picture below shows what the angles represent, s=theta in the range 0 to 2*PI in the xy-plane, and t=phi in the range 0 to PI.

    0 讨论(0)
  • 2020-11-30 05:32

    The accepted answer did not seem to support negative x values (possibly I did something wrong), but just in case, using notation from ISO convention on coordinate systems defined in this Wikipedia entry, this system of equations should work:

    import math
    
    x = radius * sin(theta) * cos(phi)
    y = radius * sin(theta) * sin(phi)
    z = radius * cos(theta)
    
    radius = math.sqrt(math.pow(x, 2) + math.pow(y, 2) + math.pow(z, 2))
    
    phi = math.atan2(y, x)
    theta = math.acos((z / radius))
    
    0 讨论(0)
提交回复
热议问题