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
| 1 | 1 | #Using Map function to convert F to C | |
| 2 | 2 | def map(value, fromLow, fromHigh, toLow, toHigh): | |
| 3 | 3 | fromRange = fromHigh - fromLow | |
| 4 | 4 | toRange = toHigh - toLow | |
| 5 | 5 | scaleFactor = toRange / fromRange | |
| 6 | 6 | tmpValue = value - fromLow | |
| 7 | 7 | tmpValue *= scaleFactor | |
| 8 | 8 | return tmpValue + toLow | |
| 9 | 9 | ||
| 10 | 10 | for tempF in range(-100,220,2): | |
| 11 | 11 | tempC=map(tempF,32,212,0,100) | |
| 12 | 12 | print(F"F={tempF} tempC={tempC}") | |
| 13 | 13 | ||
| 14 | 14 | ||
| 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 | |
| 24 | 24 | ||
| 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 | |
| 28 | 28 | ||
| 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)) | |
| 32 | 32 | ||
| 33 | - | ||
| 33 | + | return x,y,z | |
| 34 | 34 | ||
| 35 | 35 | ||
| 36 | 36 |
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.
python.kpaste.net RSS