pastebin - collaborative debugging tool
python.kpaste.net RSS

Difference between
modified post 61a0c by Anonymous on Sat 30th Jan 2021 01:09
original post f43d by Anonymous on Tue 18th Feb 2020 17:29
Download diff
Show old version | new version | both versions

    
11
#Using Map function to convert F to C
22
def map(value, fromLow, fromHigh, toLow, toHigh):
33
    fromRange = fromHigh - fromLow
44
    toRange = toHigh - toLow
55
    scaleFactor = toRange / fromRange
66
    tmpValue = value - fromLow
77
    tmpValue *= scaleFactor
88
    return tmpValue + toLow
99
1010
for tempF in range(-100,220,2):
1111
    tempC=map(tempF,32,212,0,100)
1212
    print(F"F={tempF} tempC={tempC}")
1313
1414
15-
15+
def cartesianToSpherical(x, y, z):
16-
16+
    theta = math.degrees(math.atan2(math.sqrt((x*x)+(y*y)),z))
17-
17+
    phi = math.degrees(math.atan2(x,y))
18-
18+
    if (theta < 0):
19-
19+
        theta = 360 + theta
20-
20+
    if (phi < 0):
21-
21+
        phi = 360 + phi
22-
22+
    radius = math.sqrt((x * x) + (y * y) + (z * z))
23-
23+
    return theta, phi, radius
2424
25-
25+
def sphericalToCartesian(centerX, centerY, centerZ, radius, theta, phi):
26-
26+
    thetaRadians = (theta) * math.pi / 180.0
27-
27+
    phiRadians = (phi) * math.pi / 180.0
2828
29-
29+
    x = centerY + (radius * math.sin(phiRadians) * math.sin(thetaRadians))
30-
30+
    y = centerX + (radius * math.cos(phiRadians) * math.sin(thetaRadians))
31-
31+
    z = centerZ + (radius * math.cos(thetaRadians))
3232
33-
33+
    return x,y,z
3434
3535
3636

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at