Finding y-coordinate in Quad

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
kubatp
Gnome
Posts: 354
Joined: Tue Jan 06, 2009 1:12 pm
x 7

Finding y-coordinate in Quad

Post by kubatp » Mon Mar 30, 2015 8:31 pm

Hi,
I create a manual object with quads and I keep the coordinates in memory array. I later need to find out a height (y-coordinate) of the point on this manual object. Manual object is a grid and from the grid I have closest corners (p1, p2, p3 and p4). Somewhere in the quad is a point for which I have x and z coordinate and I need to find y.
Is there an easy way to get it?
xCoordinateInQuad.png
Thank you for help
0 x

kubatp
Gnome
Posts: 354
Joined: Tue Jan 06, 2009 1:12 pm
x 7

Re: Finding y-coordinate in Quad

Post by kubatp » Tue Mar 31, 2015 9:20 pm

Nobody can help me here? I presumed that many people had similar problems already
0 x

User avatar
Herb
Orc
Posts: 412
Joined: Thu Jun 04, 2009 3:21 am
Location: Kalamazoo,MI
x 1

Re: Finding y-coordinate in Quad

Post by Herb » Tue Mar 31, 2015 9:52 pm

Yes, I've done something similar. I have a large quad and I needed to get the X,Y on it when I click the mouse on the Ogre::Plane. So, I used the wiki's article on Raycasting to the polygon level to do it. Basically you could tweak it to send a raycast from above (doesn't have to be mouse click based) down on your shape to get an intersection to get the Y value. Basic raycasting doesn't work as it's by bounding box, but this article has sample code to get down to the polygon level which will get you the precision you need.
0 x

scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 2

Re: Finding y-coordinate in Quad

Post by scrawl » Tue Mar 31, 2015 9:56 pm

This is more of a linear algebra question than an Ogre question, I'm sure you could find a better explanation on other sites.
Check which triangle the point is on. Define a plane equation for that triangle using the 3 points notation. Then solve the plane equation using the s and t values that define your target point.
0 x

kubatp
Gnome
Posts: 354
Joined: Tue Jan 06, 2009 1:12 pm
x 7

Re: Finding y-coordinate in Quad

Post by kubatp » Tue Mar 31, 2015 10:02 pm

Hi,
thank you for your replies.
Herb wrote:I used the wiki's article on Raycasting to the polygon level to do it
Yes, I considered this option, but I dont really want to do raycasting when I can solve this mathematically.
scrawl wrote:This is more of a linear algebra question
Yes, you are absolutely right. I just wanted to ask if anyone else was already solving this problem and might give me a quick answer. I simply thought that this is something many people solved already before and I didn't want to reinvent the wheel.
0 x

User avatar
c6burns
Beholder
Posts: 1511
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines

Re: Finding y-coordinate in Quad

Post by c6burns » Tue Mar 31, 2015 10:07 pm

It's not really an Ogre question, but ...

Equation of plane:
Ax + By + Cz + D = 0

Algebra:
By = -Ax - Cz - D
y = (-Ax - Cz - D) / B

A, B, C and D are known because you defined the plane. So ... plug in your known x and z values to find y. If unclear, google it because I am so shit at maths, so if I'm explaining to this to you then you need to do some reading. I remember covering this in high school algebra.

You can see an implementation of this in Terrain::getHeightAtTerrainPosition where it returns: (note: it treats height as z)
(-plane.normal.x * x - plane.normal.y * y - plane.d) / plane.normal.z;

EDIT: Ah you bums posted while I was posting :lol:
0 x

kubatp
Gnome
Posts: 354
Joined: Tue Jan 06, 2009 1:12 pm
x 7

Re: Finding y-coordinate in Quad

Post by kubatp » Tue Apr 07, 2015 10:25 am

Hi,
thank you very much for your help, especially pointing to this getHeightAtTerrainPosition. It helped me a lot and solved the problem.
0 x

Post Reply