pastebin - collaborative debugging tool
python.kpaste.net RSS


Map Function c22 s2c
Posted by Anonymous on Sat 30th Jan 2021 01:09
raw | new post
modification of post by Anonymous (view diff)

  1. #Using Map function to convert F to C
  2. def map(value, fromLow, fromHigh, toLow, toHigh):
  3.     fromRange = fromHigh - fromLow
  4.     toRange = toHigh - toLow
  5.     scaleFactor = toRange / fromRange
  6.     tmpValue = value - fromLow
  7.     tmpValue *= scaleFactor
  8.     return tmpValue + toLow
  9.  
  10. for tempF in range(-100,220,2):
  11.     tempC=map(tempF,32,212,0,100)
  12.     print(F"F={tempF} tempC={tempC}")
  13.    
  14.  
  15. def cartesianToSpherical(x, y, z):
  16.     theta = math.degrees(math.atan2(math.sqrt((x*x)+(y*y)),z))
  17.     phi = math.degrees(math.atan2(x,y))
  18.     if (theta < 0):
  19.         theta = 360 + theta
  20.     if (phi < 0):
  21.         phi = 360 + phi
  22.     radius = math.sqrt((x * x) + (y * y) + (z * z))
  23.     return theta, phi, radius
  24.  
  25. def sphericalToCartesian(centerX, centerY, centerZ, radius, theta, phi):
  26.     thetaRadians = (theta) * math.pi / 180.0
  27.     phiRadians = (phi) * math.pi / 180.0
  28.  
  29.     x = centerY + (radius * math.sin(phiRadians) * math.sin(thetaRadians))
  30.     y = centerX + (radius * math.cos(phiRadians) * math.sin(thetaRadians))
  31.     z = centerZ + (radius * math.cos(thetaRadians))
  32.  
  33.     return x,y,z

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