# Creating a function that will calculate the equation of a line in 3D space

**URL:** <https://discourse.processing.org/t/creating-a-function-that-will-calculate-the-equation-of-a-line-in-3d-space/1597>\
**Category:** Coding Questions\
**Created:** [July 8, 2018, 5:42pm UTC](https://discourse.processing.org/t/creating-a-function-that-will-calculate-the-equation-of-a-line-in-3d-space/1597 "2018-07-08T17:42:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott06](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@Scott06](https://discourse.processing.org/u/Scott06)\
**Post date:** [July 8, 2018, 5:42pm UTC](https://discourse.processing.org/t/creating-a-function-that-will-calculate-the-equation-of-a-line-in-3d-space/1597/1 "2018-07-08T17:42:08Z")

</div>

Hi, I am in need of some help. I am currently writing a program that will take a camera position and a point in space and project that point onto a 2D image plane. One function that I need to create is to create a function that gives an equation of a line (in parametric form) given two points (the camera position and the random point). I know how to do this with pen and paper [https://www.youtube.com/watch?v=iqJ9vaPoHkQ&t=309s](https://www.youtube.com/watch?v=iqJ9vaPoHkQ&t=309s)  
but I don’t know how to program this. Thanks!

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 8, 2018, 10:31pm UTC](https://discourse.processing.org/t/creating-a-function-that-will-calculate-the-equation-of-a-line-in-3d-space/1597/2 "2018-07-08T22:31:38Z")

</div>

From what I understand, you need the camera position? [https://processing.org/reference/camera\_.html](https://processing.org/reference/camera_.html)

If you generate a random point in 3D space, then you should be able to trace the line using the provided `line()` function.

Are you changing the camera position in your code?

Do

---

<div class="post-metadata">

**Author:** ![codingking03](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@codingking03](https://discourse.processing.org/u/codingking03)\
**Post date:** [July 9, 2018, 12:57am UTC](https://discourse.processing.org/t/creating-a-function-that-will-calculate-the-equation-of-a-line-in-3d-space/1597/3 "2018-07-09T00:57:27Z")

</div>

you need two functions for a line

y=mx+b  
z=mx+b

then x++;

plug i nm and b

---

<div class="post-metadata">

**Author:** ![codingking03](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@codingking03](https://discourse.processing.org/u/codingking03)\
**Post date:** [July 9, 2018, 12:58am UTC](https://discourse.processing.org/t/creating-a-function-that-will-calculate-the-equation-of-a-line-in-3d-space/1597/4 "2018-07-09T00:58:09Z")

</div>

of course you would have remember that the y values go down etc.
