本文整理汇总了Python中math.pi方法的典型用法代码示例。如果您正苦于以下问题:Python math.pi方法的具体用法?Python math.pi怎么用?Python math.pi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math
的用法示例。
在下文中一共展示了math.pi方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: step
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def step(self, amt=1):
for i in range(self._size):
y = math.sin(
math.pi *
float(self.cycles) *
float(self._step * i) /
float(self._size))
if y >= 0.0:
# Peaks of sine wave are white
y = 1.0 - y # Translate Y to 0.0 (top) to 1.0 (center)
r, g, b = self.palette(0)
c2 = (int(255 - float(255 - r) * y),
int(255 - float(255 - g) * y),
int(255 - float(255 - b) * y))
else:
# Troughs of sine wave are black
y += 1.0 # Translate Y to 0.0 (bottom) to 1.0 (center)
r, g, b = self.palette(0)
c2 = (int(float(r) * y),
int(float(g) * y),
int(float(b) * y))
self.layout.set(self._start + i, c2)
self._step += amt
示例2: _get_observation_upper_bound
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def _get_observation_upper_bound(self):
"""Get the upper bound of the observation.
Returns:
The upper bound of an observation. See GetObservation() for the details
of each element of an observation.
"""
upper_bound = np.zeros(self._get_observation_dimension())
num_motors = self.minitaur.num_motors
upper_bound[0:num_motors] = math.pi # Joint angle.
upper_bound[num_motors:2 * num_motors] = (
motor.MOTOR_SPEED_LIMIT) # Joint velocity.
upper_bound[2 * num_motors:3 * num_motors] = (
motor.OBSERVED_TORQUE_LIMIT) # Joint torque.
upper_bound[3 * num_motors:] = 1.0 # Quaternion of base orientation.
return upper_bound
示例3: MapToMinusPiToPi
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def MapToMinusPiToPi(angles):
"""Maps a list of angles to [-pi, pi].
Args:
angles: A list of angles in rad.
Returns:
A list of angle mapped to [-pi, pi].
"""
mapped_angles = copy.deepcopy(angles)
for i in range(len(angles)):
mapped_angles[i] = math.fmod(angles[i], TWO_PI)
if mapped_angles[i] >= math.pi:
mapped_angles[i] -= TWO_PI
elif mapped_angles[i] < -math.pi:
mapped_angles[i] += TWO_PI
return mapped_angles
示例4: ResetTerrainExample
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def ResetTerrainExample():
"""An example showing resetting random terrain env."""
num_reset = 10
steps = 100
env = minitaur_randomize_terrain_gym_env.MinitaurRandomizeTerrainGymEnv(
render=True,
leg_model_enabled=False,
motor_velocity_limit=np.inf,
pd_control_enabled=True)
action = [math.pi / 2] * 8
for _ in xrange(num_reset):
env.reset()
for _ in xrange(steps):
_, _, done, _ = env.step(action)
if done:
break
示例5: _gen_signal
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def _gen_signal(self, t, phase):
"""Generates a sinusoidal reference leg trajectory.
The foot (leg tip) will move in a ellipse specified by extension and swing
amplitude.
Args:
t: Current time in simulation.
phase: The phase offset for the periodic trajectory.
Returns:
The desired leg extension and swing angle at the current time.
"""
period = 1 / self._step_frequency
extension = self._extension_amplitude * math.cos(
2 * math.pi / period * t + phase)
swing = self._swing_amplitude * math.sin(2 * math.pi / period * t + phase)
return extension, swing
示例6: _signal
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def _signal(self, t):
"""Generates the trotting gait for the robot.
Args:
t: Current time in simulation.
Returns:
A numpy array of the reference leg positions.
"""
# Generates the leg trajectories for the two digonal pair of legs.
ext_first_pair, sw_first_pair = self._gen_signal(t, 0)
ext_second_pair, sw_second_pair = self._gen_signal(t, math.pi)
trotting_signal = np.array([
sw_first_pair, sw_second_pair, sw_second_pair, sw_first_pair,
ext_first_pair, ext_second_pair, ext_second_pair, ext_first_pair
])
signal = np.array(self._init_pose) + trotting_signal
return signal
示例7: _get_observation
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def _get_observation(self):
world_translation_minitaur, world_rotation_minitaur = (
self._pybullet_client.getBasePositionAndOrientation(
self.minitaur.quadruped))
world_translation_ball, world_rotation_ball = (
self._pybullet_client.getBasePositionAndOrientation(self._ball_id))
minitaur_translation_world, minitaur_rotation_world = (
self._pybullet_client.invertTransform(world_translation_minitaur,
world_rotation_minitaur))
minitaur_translation_ball, _ = (
self._pybullet_client.multiplyTransforms(minitaur_translation_world,
minitaur_rotation_world,
world_translation_ball,
world_rotation_ball))
distance = math.sqrt(minitaur_translation_ball[0]**2 +
minitaur_translation_ball[1]**2)
angle = math.atan2(minitaur_translation_ball[0],
minitaur_translation_ball[1])
self._observation = [angle - math.pi / 2, distance]
return self._observation
示例8: _get_observation_upper_bound
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def _get_observation_upper_bound(self):
"""Get the upper bound of the observation.
Returns:
The upper bound of an observation. See _get_true_observation() for the
details of each element of an observation.
"""
upper_bound_roll = 2 * math.pi
upper_bound_pitch = 2 * math.pi
upper_bound_roll_dot = 2 * math.pi / self._time_step
upper_bound_pitch_dot = 2 * math.pi / self._time_step
upper_bound_motor_angle = 2 * math.pi
upper_bound = [
upper_bound_roll, upper_bound_pitch, upper_bound_roll_dot,
upper_bound_pitch_dot
]
if self._use_angle_in_observation:
upper_bound.extend([upper_bound_motor_angle] * NUM_MOTORS)
return np.array(upper_bound)
示例9: ResetPoseExample
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def ResetPoseExample(log_path=None):
"""An example that the minitaur stands still using the reset pose."""
steps = 10000
environment = minitaur_gym_env.MinitaurGymEnv(
urdf_version=minitaur_gym_env.DERPY_V0_URDF_VERSION,
render=True,
leg_model_enabled=False,
motor_velocity_limit=np.inf,
pd_control_enabled=True,
accurate_motor_model_enabled=True,
motor_overheat_protection=True,
hard_reset=False,
log_path=log_path)
action = [math.pi / 2] * 8
for _ in range(steps):
_, _, done, _ = environment.step(action)
time.sleep(1./100.)
if done:
break
示例10: sample
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def sample(self):
"""Samples new points around some existing point.
Removes the sampling base point and also stores the new jksampled points if
they are far enough from all existing points.
"""
active_point = self._active_list.pop()
for _ in xrange(self._max_sample_size):
# Generate random points near the current active_point between the radius
random_radius = np.random.uniform(self._min_radius, 2 * self._min_radius)
random_angle = np.random.uniform(0, 2 * math.pi)
# The sampled 2D points near the active point
sample = random_radius * np.array(
[np.cos(random_angle), np.sin(random_angle)]) + active_point
if not self._is_in_grid(sample):
continue
if self._is_close_to_existing_points(sample):
continue
self._active_list.append(sample)
self._grid[self._point_to_index_1d(sample)] = sample
示例11: ResetPoseExample
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def ResetPoseExample():
"""An example that the minitaur stands still using the reset pose."""
steps = 1000
randomizer = (minitaur_env_randomizer.MinitaurEnvRandomizer())
environment = minitaur_gym_env.MinitaurBulletEnv(
render=True,
leg_model_enabled=False,
motor_velocity_limit=np.inf,
pd_control_enabled=True,
accurate_motor_model_enabled=True,
motor_overheat_protection=True,
env_randomizer = randomizer,
hard_reset=False)
action = [math.pi / 2] * 8
for _ in range(steps):
_, _, done, _ = environment.step(action)
if done:
break
environment.reset()
示例12: ConvertFromLegModel
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def ConvertFromLegModel(self, actions):
"""Convert the actions that use leg model to the real motor actions.
Args:
actions: The theta, phi of the leg model.
Returns:
The eight desired motor angles that can be used in ApplyActions().
"""
motor_angle = copy.deepcopy(actions)
scale_for_singularity = 1
offset_for_singularity = 1.5
half_num_motors = int(self.num_motors / 2)
quater_pi = math.pi / 4
for i in range(self.num_motors):
action_idx = i // 2
forward_backward_component = (-scale_for_singularity * quater_pi * (
actions[action_idx + half_num_motors] + offset_for_singularity))
extension_component = (-1)**i * quater_pi * actions[action_idx]
if i >= half_num_motors:
extension_component = -extension_component
motor_angle[i] = (
math.pi + forward_backward_component + extension_component)
return motor_angle
示例13: __init__
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def __init__(self, urdfRootPath=pybullet_data.getDataPath(), timeStep=0.01):
self.urdfRootPath = urdfRootPath
self.timeStep = timeStep
self.maxVelocity = .35
self.maxForce = 200.
self.fingerAForce = 2
self.fingerBForce = 2.5
self.fingerTipForce = 2
self.useInverseKinematics = 1
self.useSimulation = 1
self.useNullSpace =21
self.useOrientation = 1
self.kukaEndEffectorIndex = 6
self.kukaGripperIndex = 7
#lower limits for null space
self.ll=[-.967,-2 ,-2.96,0.19,-2.96,-2.09,-3.05]
#upper limits for null space
self.ul=[.967,2 ,2.96,2.29,2.96,2.09,3.05]
#joint ranges for null space
self.jr=[5.8,4,5.8,4,5.8,4,6]
#restposes for null space
self.rp=[0,0,0,0.5*math.pi,0,-math.pi*0.5*0.66,0]
#joint damping coefficents
self.jd=[0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001]
self.reset()
示例14: ResetPoseExample
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def ResetPoseExample(steps):
"""An example that the minitaur stands still using the reset pose."""
environment = pybullet_sim_gym_env.PyBulletSimGymEnv(
pybullet_sim_factory=boxstack_pybullet_sim,
debug_visualization=False,
render=True, action_repeat=30)
action = [math.pi / 2] * 8
vid = video_recorder.VideoRecorder(env=environment,path="vid.mp4")
for _ in range(steps):
print(_)
startsim = time.time()
_, _, done, _ = environment.step(action)
stopsim = time.time()
startrender = time.time()
#environment.render(mode='rgb_array')
vid.capture_frame()
stoprender = time.time()
print ("env.step " , (stopsim - startsim))
print ("env.render " , (stoprender - startrender))
if done:
environment.reset()
示例15: calculate_camera_variables
# 需要导入模块: import math [as 别名]
# 或者: from math import pi [as 别名]
def calculate_camera_variables(eye, lookat, up, fov, aspect_ratio, fov_is_vertical=False):
import numpy as np
import math
W = np.array(lookat) - np.array(eye)
wlen = np.linalg.norm(W)
U = np.cross(W, np.array(up))
U /= np.linalg.norm(U)
V = np.cross(U, W)
V /= np.linalg.norm(V)
if fov_is_vertical:
vlen = wlen * math.tan(0.5 * fov * math.pi / 180.0)
V *= vlen
ulen = vlen * aspect_ratio
U *= ulen
else:
ulen = wlen * math.tan(0.5 * fov * math.pi / 180.0)
U *= ulen
vlen = ulen * aspect_ratio
V *= vlen
return U, V, W