# Line-Plane Intersection

Page 1 of 1

## 0 Replies - 360 Views - Last Post: 26 January 2014 - 08:11 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=339000&amp;s=b04edac20214b43f4043ac7cac9869aa&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 zFollette

• New D.I.C Head

Reputation: 0
• Posts: 1
• Joined: 26-January 14

# Line-Plane Intersection

Posted 26 January 2014 - 08:11 PM

I am making a Ray Picking method for my game (LWJGL), so far the only thing that works in that method is Line-Plane intersection when the player is clicking 100% perpendicular to the surface of the plane. This is because when making an equation for the plane using 3 points (1, 0, -1)(0, 1, -1)(1, 1, -1), the equation only needs to utilize the Z axis. Is there any way to account for the X and Y axes?

The code I am currently using:
```  Vector3f A = new Vector3f(1, 0, -1);
Vector3f B = new Vector3f(0, 1, -1);
Vector3f C = new Vector3f(1, 1, -1);

Vector3f v1 = new Vector3f(B.x - A.x, B.y - A.y, B.z - A.z);
Vector3f v2 = new Vector3f(C.x - A.x, C.y - A.y, C.z - A.z);

float[] i = new float[]{v1.x, v2.x};
float[] j = new float[]{v1.y, v2.y};
float[] k = new float[]{v1.z, v2.z};

float a = (j[0] * k[1]) - (j[1] * k[0]);
float b = (i[0] * k[1]) - (i[1] * k[0]);
float c = (i[0] * j[1]) - (i[1] * j[0]);

float eX = ((a * -C.x));
float eY = ((b * -C.y));
float eZ = ((c * -C.z));

Vector3f v3 = start;
Vector3f v4 = new Vector3f(end.x - v3.x, end.y - v3.y, end.z - v3.z);

float tX = v4.x, tY = v4.y, tZ = v4.z;
float x, y, z;

float rem = (((a * v3.x) + eX + (b * v3.y) + eY + (c * v3.z) + eZ));
float t = rem / (tX + tY + tZ);

x = v3.x + (tX * t);
y = v3.y + (tY * t);
z = v3.z + (tZ * t);

Vector3f v5 = new Vector3f(x, y, z);
```

The equation for that plane is
```(-z - 1 = 0)
```
So clearly it will not work if you change the X and Y axis values. So does anyone know how to get the line-plane intersect while relying on all axes?

Here is what happens when I cast a ray perpendicular to the plane:

And this is what happens when I am not perpendicular to the plane:

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }