# Planar equation from camera image

**URL:** <https://discourse.processing.org/t/planar-equation-from-camera-image/8164>\
**Category:** Project Guidance\
**Created:** [February 6, 2019, 5:47pm UTC](https://discourse.processing.org/t/planar-equation-from-camera-image/8164 "2019-02-06T17:47:44Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [February 9, 2019, 8:24pm UTC](https://discourse.processing.org/t/planar-equation-from-camera-image/8164/2 "2019-02-09T20:24:23Z")

</div>

I can’t tell from your question what you are trying to solve, but I’m guessing that you either want to use `screenX()` or `modelX()`  
(and Y, and Z).

> **[screenX() / Reference](https://processing.org/reference/screenX_.html)**
>
> Takes a three-dimensional X, Y, Z position and returns the X value for where it will appear on a (two-dimensional) screen.

> **[modelX() / Reference](https://processing.org/reference/modelX_.html)**
>
> Returns the three-dimensional X, Y, Z position in model space. This returns the X value for a given coordinate based on the current set of transformations (scale, rotate, translate, etc.) The X value …

If you could provide a very simple MCVE in which you draw your plane in P3D then it would be easier to give you more advice.

If this is actually object based problem, there are also approaches like the Picking library. Or if for some reason you can’t use screenX, you could implement something like ray tracing –

or you could try to just compute a simple line-plane intersection. This is untested:

> <https://stackoverflow.com/questions/5666222/3d-line-plane-intersection/52711312#52711312>

…but you could follow this Java example approach using PVector.dot(). In order to project the line you need to know the camera location

> **[camera() / Reference](https://processing.org/reference/camera_.html)**
>
> Sets the position of the camera through setting the eye position, the center of the scene, and which axis is facing upward. Moving the eye position and the direction it is pointing (the center of the …

The key fact there is that the default eyeZ is `(height/2.0) / tan(PI*30.0 / 180.0)`– so your line works like this:

```auto
PVector ray1 = (width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0));
PVector ray2 = (pp1x, pp1y, 0); // eg mouseX, mouseY

```

…and then you solve for p1 using line-plane intersection, as per [3D Line-Plane Intersection - Stack Overflow](https://stackoverflow.com/a/52711312/7207622)

You might also be interested in this recent related post:

> [@Computing polygon normal with Newell's method](https://discourse.processing.org/t/computing-polygon-normal-with-newells-method/8116):
>
> Hi guys, I’m having difficulties computing the normal of a polygon (more than 3 vertices) based on the Newell’s method. 𝑛𝑥=∑𝑖=0𝑛(𝑦𝑖−𝑦𝑖+1)(𝑧𝑖+𝑧𝑖+1) 𝑛𝑦=∑𝑖=0𝑛(𝑧𝑖−𝑧𝑖+1)(𝑥𝑖+𝑥𝑖+1) 𝑛𝑧=∑𝑖=0𝑛(𝑥𝑖−𝑥𝑖+1)(𝑦𝑖+𝑦𝑖+1) It seems pretty straightforward and I’ve seen various implementations (in [Java](https://github.com/Syntopia/Meshia/blob/master/hemesh/wblut/hemesh/HE_Face.java) (line 123), in [C++](http://www.dillonbhuff.com/?p=284) or in [Python](https://stackoverflow.com/questions/39001642/calculating-surface-normal-in-python-using-newells-method)) and yet mine gives me very strange results: def computePolyNormal(face): #Calculate normal with Newell's method nml =…

---

_[View the full topic](https://discourse.processing.org/t/planar-equation-from-camera-image/8164)._
