<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alex on Medium]]></title>
        <description><![CDATA[Stories by Alex on Medium]]></description>
        <link>https://medium.com/@alexbates39?source=rss-ae37f0ffb08f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Alex on Medium</title>
            <link>https://medium.com/@alexbates39?source=rss-ae37f0ffb08f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 14:02:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alexbates39/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[An Overview of the Three.js Coordinate System]]></title>
            <link>https://medium.com/@alexbates39/an-overview-of-the-three-js-coordinate-system-07f75ee76e64?source=rss-ae37f0ffb08f------2</link>
            <guid isPermaLink="false">https://medium.com/p/07f75ee76e64</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[3d-modeling]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[threejs]]></category>
            <dc:creator><![CDATA[Alex]]></dc:creator>
            <pubDate>Thu, 04 Jan 2024 04:29:13 GMT</pubDate>
            <atom:updated>2024-01-04T04:29:13.489Z</atom:updated>
            <content:encoded><![CDATA[<h4>A visual guide to positioning elements in Three.js and React Three Fiber.</h4><figure><img alt="Purple handwriting typeface that writes “Three.js: Coordinate System”" src="https://cdn-images-1.medium.com/max/1024/1*mbDYiKm6UEahvoS8UJAhBA.png" /></figure><p>I recently started working with <a href="https://threejs.org/">Three.js</a>, a JavaScript library used to create 3D graphics that can be displayed in the browser, and <a href="https://docs.pmnd.rs/react-three-fiber/getting-started/introduction">React Three Fiber</a>. I quickly came to realize the importance of understanding its coordinate system, as it is required for positioning <em>everything</em> — objects, lighting, cameras…</p><p>After learning that Three.js uses a right-handed coordinate system, I had a difficult time at first trying to imagine how different coordinate values would appear visually in the browser. So, I decided to place three cubes in a canvas to test out different position values and compare them to one another. (If you’re also just getting into Three.js or R3F, I highly recommend doing something like this on your own as well — it’s a great way to experiment with and better grasp the three-dimensional canvas space.)</p><p>Here is an overview of how the Three.js coordinate system works:</p><h4>The Three Coordinate Values: [x, y, z]</h4><p>This is pretty straightforward. We’re working with a three-dimensional space that has three coordinate axes: <em>x</em>, <em>y</em>, and <em>z</em>. The coordinates are represented in Three.js as such: [x, y, z].</p><pre>// coordinate values are written as [x, y, z]<br><br>// for example:<br>&lt;Canvas camera={{ position: [0,-1,3]}}&gt; // in this case x = 0, y = -1, z = 3</pre><p>Three.js uses a <strong>right-handed coordinate system</strong>, which the figure below demonstrates. This means that, with all axes perpendicular to one another, if the <em>y</em>-axis is pointing upwards and the <em>x</em>-axis pointing right, then the <em>z</em>-axis is pointing towards you and is coming out of the screen.</p><figure><img alt="On the left is a diagram of the axes of the left-handed cartesian coordinates, and below is a left hand with the palm facing upwards. To the right is an axes diagram of the right-handed cartesian coordinates, below it is a right hand with the palm facing upwards." src="https://cdn-images-1.medium.com/max/360/1*H61WmcUOzq-w-RSO488y8A.gif" /><figcaption>The left-handed coordinate system (left) and the right-handed coordinate system (right). (Source: <a href="https://learn.microsoft.com/en-us/previous-versions/windows/desktop/bb324490%28v=vs.85%29">Microsoft</a>)</figcaption></figure><p>Now that we know this, let’s take a look at how different values in each coordinate will affect the position of an object in the browser.</p><h4>The x-coordinate</h4><p>If <em>x = </em>0 is the center, then positive <em>x</em>-coordinate values will shift an object to the right, while negative values will shift it to the left. <strong>Increasing the <em>x</em>-coordinate moves an object further right and decreasing the <em>x </em>value moves it further to the left.</strong></p><figure><img alt="A blue cube to the left with position of [-1, 0, 0] and an x-coordinate of -1. A red cube in the center with position [0, 0, 0] and x-coordinate of 0. A purple cube to the right with position [1, 0, 0] and x-coordinate of 1. All cubes are evenly spaced out horizontally and are on the same horizontal plane." src="https://cdn-images-1.medium.com/max/1024/1*IS0QPc6WC1f_HUIk6TkFhA.png" /><figcaption>Three cubes with different x-coordinates. Image by the author.</figcaption></figure><h4>The y-coordinate</h4><p>Next, with <em>y</em> <em>= </em>0 positioned at the center, positive <em>y </em>values will shift an object upwards while negative values move it downwards. <strong>Increasing the <em>y</em>-coordinate shifts an object up and decreasing shifts it down.</strong></p><figure><img alt="A blue cube on the bottom with position of [0, -1, 0] and an y-coordinate of -1. A red cube in the center with position [0, 0, 0] and y-coordinate of 0. A purple cube at the top with position [0, 1, 0] and y-coordinate of 1. All cubes are evenly spaced out vertically and are on the same vertical plane." src="https://cdn-images-1.medium.com/max/1024/1*KqaRvaAxqiKQhLpu6G4HEQ.png" /><figcaption>Three cubes with different y-coordinates. Image by the author.</figcaption></figure><h4>The z-coordinate</h4><p>Finally, we have the <em>z</em>-coordinate. This is where it can get a bit confusing. Remember, the positive <em>z</em>-axis is coming <em>out</em> of the screen. Therefore, <strong>increasing the <em>z</em>-coordinate moves an object outwards</strong>, <strong>relative to the screen</strong> (or positioning of the camera — more on that later), <strong>and decreasing the <em>z</em>-coordinate value moves it inwards</strong>. In other words, assuming that the object is in our field of view, then an object appears larger (and thus closer) as the <em>z</em>-coordinate increases, while it appears smaller (and further away) as the<em> z</em>-coordinate decreases.</p><figure><img alt="A blue cube to the left with position of [-1, 0, -1] and an z-coordinate of -1. A red cube in the center with position [0, 0, 0] and z-coordinate of 0. A purple cube to the right with position [1, 0, 1] and z-coordinate of 1. The blue cube is the smallest, followed by the red cube, and the purple cube is the largest. All cubes are on the same diagonal plane." src="https://cdn-images-1.medium.com/max/1024/1*EJByuF99E2fIfyJWuJzASg.png" /><figcaption>Three cubes with different z-coordinates. Image by the author.</figcaption></figure><p>It’s important to note that in the figure above, the x-coordinates are spaced out by 1 unit in order to make the effect of changing the z-coordinate value visible from the front.</p><p>The camera, in all three of the above instances, is placed at [0, 0, 3], but what does that mean?</p><h4>It’s all about perspective…</h4><p>We also need to take camera positioning into consideration. The camera is the lens, or the perspective, from which we view our scene, and it uses the same coordinate system and 3D space as objects on the canvas. I found an article by fellow Medium writer <a href="https://medium.com/u/af1efa4046e0">Gopisaikrishna Vuta</a> that provides a very informative look (no pun intended) into the different cameras in Three.js and how each works, which I recommend reading if you’d like to learn more:</p><p><a href="https://medium.com/@gopisaikrishna.vuta/exploring-cameras-in-three-js-32e268a6bebd">Exploring Cameras in Three.js</a></p><p>I won’t go into too much detail here, but what’s important to keep in mind is that <strong>the positioning of the camera affects the display of objects on the screen</strong> (or how it’s perceived by the user). For example, if a cube has the coordinates [0, 0, 2] but the camera is positioned at [0, 0, 0], you would not be able to see the cube on the screen because it would be <em>behind</em> the camera, or your field of view.</p><p>Similarly, let’s take a look at these three cubes:</p><pre>&lt;Cube position={[0, 0, -1]} color=&quot;blue&quot; /&gt; // the blue cube<br>&lt;Cube position={[0, 0, 0]} color=&quot;red&quot; /&gt; // the red cube<br>&lt;Cube position={[0, 0, 1]} color=&quot;purple&quot; /&gt; // the purple cube</pre><p>We have three cubes with <em>x</em> = 0 and <em>y</em> = 0 but different <em>z</em>-coordinates, and these will appear differently depending on where the camera is positioned. If the camera is placed at [0, 0, 3], it will look like this on the browser:</p><figure><img alt="Four labels that write “Camera Position: [0, 0, 3]”, “Blue Cube Position: [0, 0, -1]”, “Red Cube Position: [0, 0, 0]”, and “Purple Cube Position: [0, 0, 1]”. Only one purple cube in the center of the image is visible." src="https://cdn-images-1.medium.com/max/1024/1*MMOy4A80KQfih0-_yyGfDA.png" /><figcaption>Only the purple cube is visible when the camera is placed at [0, 0, 3]. Image by the author.</figcaption></figure><p>In the above example, the camera is placed on the same <em>x</em> and <em>y </em>plane as the cubes but has a greater <em>z-</em>coordinate. From this perspective, only the purple cube is visible because it is closest to the camera, and the other two cubes are aligned directly behind it. If the camera is placed at [0, 3, 0], with <em>y</em> = 3, all of the cubes will become visible:</p><figure><img alt="Four labels that write “Camera Position: [0, 0, 3]”, “Blue Cube Position: [0, 0, -1]”, “Red Cube Position: [0, 0, 0]”, and “Purple Cube Position: [0, 0, 1]”. Three evenly spaced cubes of equal size are aligned vertically in the center of the image, with a blue cube at the very top, a red cube in the center, and a purple cube at the bottom." src="https://cdn-images-1.medium.com/max/1024/1*aBd2S9RX31zQSA62MdCgMQ.png" /><figcaption>All cubes appear vertically aligned in the center of the screen when the camera is placed at [0, 3, 0]. Image by the author.</figcaption></figure><p>Even though the cubes are still in the same <em>x</em> and <em>y</em> planes, we can now see all three cubes aligned vertically at the center of the because the camera is placed <em>above</em> them.</p><p>I can go into more depth about this in an upcoming article, but I do (again) suggest experimenting with different camera positions on your own to get an idea of how it all works.</p><p>I hope that this article provides a bit more clarity about how the coordinate system in Three.js works and gives you an idea of how to position different elements within the canvas. There is a lot more that we could go into, such as the various types of cameras and lighting, but understanding the basic coordinate system and its presentation in the browser is essential to learning everything else and fully grasping the three-dimensional canvas space.</p><p><em>I love learning from others and hearing readers’ feedback, so feel free to share your thoughts in the comments! Cheers :)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=07f75ee76e64" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>