<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://pybullet.org/Bullet/phpBB3/app.php/feed/topic/12914" />

	<title>Real-Time Physics Simulation Forum</title>
	
	<link href="https://pybullet.org/Bullet/phpBB3/index.php" />
	<updated>2020-04-02T14:54:30+00:00</updated>

	<author><name><![CDATA[Real-Time Physics Simulation Forum]]></name></author>
	<id>https://pybullet.org/Bullet/phpBB3/app.php/feed/topic/12914</id>

		<entry>
		<author><name><![CDATA[cmon]]></name></author>
		<updated>2020-04-02T14:54:30+00:00</updated>

		<published>2020-04-02T14:54:30+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42751#p42751</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42751#p42751"/>
		<title type="html"><![CDATA[LookAt function help]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42751#p42751"><![CDATA[
Hi,<br><br>I have been trying to get an object to point at the centre while spawning randomly on a sphere in python. Specifically, the object is a gripper for machine learning tasks. I have also tried with a simple elongated rectangular prism.<br><br>I've implemented this code in python <a href="https://stackoverflow.com/questions/52413464/look-at-quaternion-using-up-vector/52551983#52551983" class="postlink">https://stackoverflow.com/questions/524 ... 3#52551983</a> as well as tried Euler angles with a restricted domain but neither works consistently.<br><br>Has anyone accomplished this? I've been trying for 2 days now and the problems I suspect comes from differing coordinate systems <br> in the URDF and Pybullet. <br><br>If the function works properly, perhaps it's something to add to Pybullet?<br><br>Euler angle code (works for most postions) <div class="codebox"><p>Code: </p><pre><code>def lookAt(position):    zangle = np.arctan(position[1] / position[0])    yangle = np.arctan(position[0] / position[2])    return p.getQuaternionFromEuler([0, yangle, zangle])</code></pre></div>Look at function translated from C (never works)<div class="codebox"><p>Code: </p><pre><code>def lookAt(centre, target, worldUp):    F = (target - centre) / np.linalg.norm(target - centre)    R = np.cross(F, worldUp) / np.linalg.norm(np.cross(F, worldUp))    U = np.cross(R, F)    q = Quaternion()    trace = R[0] + U[1] + F[2]    if trace &gt; 0:        s = 0.5 / np.sqrt(trace + 1.0)        q = Quaternion(0.25 / s, (U[2] - F[1]) * s, (F[0] - R[2]) * s, (R[1] - U[0]) * s)    else:        if R[0] &gt; U[1] and R[0] &gt; F[2]:            s = 2.0 * np.sqrt(1.0 + R[0] - U[1] - F[2])            q = Quaternion((U[2] - F[1]) / s, 0.25 * s, (U[0] + R[1]) / s, (F[0] + R[2]) / s)        elif U[1] &gt; F[2]:            s = 2.0 * np.sqrt(1.0 + U[1] - R[0] - F[2])            q = Quaternion((F[0] - R[2]) / s, (U[0] + R[1]) / s, 0.25 * s, (F[1] + U[2]) / s)        else:            s = 2.0 * np.sqrt(1.0 + F[2] - R[0] - U[1])            q = Quaternion((R[1] - U[0]) / s, (F[0] + R[2]) / s, (F[1] + U[2]) / s, 0.25 * s)    return q.elements</code></pre></div><p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13298">cmon</a> — Thu Apr 02, 2020 2:54 pm</p><hr />
]]></content>
	</entry>
	</feed>
