# Geometry construction on an inclined plane

## Recommended Posts

Pardon my question - which may sound quite obvious to pros - math is not my string subject and I am new to all this.

I am required to construct geometrical objects on an inclined plane - mostly points, lines and polygons. For example, I need to construct a regular grid by defining lines at regular intervals on this inclined plane. For the plane definition, I have been given a point on this inclined plane and a normal vector to this plane. How can I do this? One thing I can think of is to construct the geometries on XY plane and then somehow transforming them to "move" to the plane - but I could be wrong or totally off. Can someone guide me on how to accomplish this or suggest a better way? Thanks!

##### Share on other sites
Essentially what you'll need to do is create a coordinate frame for your plane and then create and manipulate the objects relative to that frame.

There's an infinite number of suitable frames, but a relatively straightforward way to generate a frame would be to compute the position from the plane normal and distance, and build the orientation using billboarding techniques (which are discussed frequently on these forums).

##### Share on other sites
Quote:
 Original post by jykEssentially what you'll need to do is create a coordinate frame for your plane and then create and manipulate the objects relative to that frame.There's an infinite number of suitable frames, but a relatively straightforward way to generate a frame would be to compute the position from the plane normal and distance, and build the orientation using billboarding techniques (which are discussed frequently on these forums).That's fairly cursory, but post back if you need more info.

Thanks for the response. I think I understand - except I am not clear on the billboarding - which I had to look up. But it is indeed very cursory for me to get going.

I think a little background will help clarify what I want to do. Imagine a house standing on a ground with its base on XY plane. I call this house in WCS - World Coordinate Space. Now I want to work on the inclined roof - so I define another coordinate space which is UCS - User-defined Coordinate Space - it will have its own origin and X,Y,Z axis. For construction purposes, all the coordinates will be in this UCS - so that they will be created in that space.

I think what I need is a means to transform points to and fro between above two coordinate systems - WCS and UCS. Does this help any better?

Thanks!

##### Share on other sites
Quote:
 I think what I need is a means to transform points to and fro between above two coordinate systems - WCS and UCS.
A simple matrix transform should do the trick (the transform itself being based on the coordinate frame I mentioned earlier).

I suspect that's not that helpful though. Do you have the information you need at this point? If not, can clarify what part you're still unclear on?

##### Share on other sites
Quote:
 Original post by jykA simple matrix transform should do the trick (the transform itself being based on the coordinate frame I mentioned earlier).I suspect that's not that helpful though. Do you have the information you need at this point? If not, can clarify what part you're still unclear on?

Unfortunately I don't know what I don't know. The question is what would be the transformation matrix and how it would be defined? I need a generic way of transforming points from one coordinate system to the other. I have the vector and matrix library that will let me do the necessary operations on them - but I am clueless to applying it to solve this problem. Can you point out any literature or tutorial or pseudo-code that shows how to do this?

##### Share on other sites
Quote:
 The question is what would be the transformation matrix and how it would be defined?
It would be the transform I described earlier. But, it sounds like you need more than just an arbitrary coordinate frame for a plane, right? If you're working on an 'inclined roof' (presumably consisting of one or more polygons), you probably need something more specific.
Quote:
 I need a generic way of transforming points from one coordinate system to the other.
That would be a transform matrix.
Quote:
 Can you point out any literature or tutorial or pseudo-code that shows how to do this?
Probably not without having a better understanding of the problem. What is the application exactly? What's the user interface like? Can you post a screenshot?

Generally speaking, I still think 'billboarding' is probably what you're looking for, more or less. But, it's hard to say for sure.

##### Share on other sites
Quote:
 Original post by jykProbably not without having a better understanding of the problem. What is the application exactly? What's the user interface like? Can you post a screenshot

Here are all the details of this application. I am implementing a software component packaged as a web service, which receives information about a roof, and performs certain operations on it and returns BOM - or Bill of Materials. The information about the roof includes, among other things, its geometry. Following geometric information is passed to this web service:

(1) Size of the rectangular roof in terms of its length and width
(2) Normal vector to this roof, and
(3) A 3D point on this roof which represents the center point of the roof

One of the operations on the roof involves its tiling, and the output is the geometry of each tile, and some other numerical information such as load on the roof, and the counts of various parts (BOM), etc. In future, there will be more operations on a roof.

As you see, there is no graphical component in this set up, hence no screenshots. The caller to this web service is responsible for the rendering aspects.

Above functionality is already implemented in AutoCAD - where there are very convenient ways of defining and working on different coordinate systems - or reference frames - and transformations thereof. I have decided to move this functionality out of AutoCAD so that it can be consumed by any client.

I hope this explains it all -

(1) Given the center point of the roof in 3D, normal to the roof, and the length and width of the roof, how can I construct a 3D polygonal geometry that represents the boundary of the roof?
(2) How can I make this polygon as my working XY plane where the given 3D point is the origin, X axis is parallel to the length, Y axis is parallel to the width?
(3) Finally, how can I transform points from such a plane back to the WCS?

Thank you for your patience and help - even if I can accomplish 91) above, it would be a valuable help.

##### Share on other sites
Quote:
 (1) Given the center point of the roof in 3D, normal to the roof, and the length and width of the roof, how can I construct a 3D polygonal geometry that represents the boundary of the roof?

I just realized that just having a normal and a point on the roof could give me the roof-plane, but not the boundary of the roof even if its dimensions are given. I think that actual 3D coordinates of the roof would be required to be given.

##### Share on other sites
Nice explanation :)

I think you hit on the crux of the problem here:
Quote:
 I just realized that just having a normal and a point on the roof could give me the roof-plane, but not the boundary of the roof even if its dimensions are given. I think that actual 3D coordinates of the roof would be required to be given.
A problem with this:
Quote:
 (1) Given the center point of the roof in 3D, normal to the roof, and the length and width of the roof, how can I construct a 3D polygonal geometry that represents the boundary of the roof?
Is that it doesn't give you enough information to construct a representation of the roof surface.

Now, most roof surfaces have characteristics that would allow us to make a reasonable guess as to the orientation of the surface, but a good example of a problem case would be a 'flat' roof surface (that is, one for which the normal points straight upwards). In this case, even if we assume the building is 'axis aligned', we still don't know which way the surface is oriented.

So, it seems to me you probably need some additional information (such as the corners of the roof or some other piece of information you can use to uniquely determine the orientation).

##### Share on other sites
Quote:
 Original post by jykSo, it seems to me you probably need some additional information (such as the corners of the roof or some other piece of information you can use to uniquely determine the orientation).

Yes, the caller can pass the actual corner coordinates of the roof - in addition to the normal and the center point. I think that should take care of the roof orientation. This roof-plane would be my construction plane on which my code would be performing operations to layout tiles, etc. I believe the main problem, in general, is how to transform points from one coordinate space to another - and defining appropriate transformation definition for that - this is what I remember from my high school math - but don't know how to do that. Is there a way to attach graphics to the messages in this forum?

##### Share on other sites
Quote:
 Yes, the caller can pass the actual corner coordinates of the roof - in addition to the normal and the center point. I think that should take care of the roof orientation. This roof-plane would be my construction plane on which my code would be performing operations to layout tiles, etc. I believe the main problem, in general, is how to transform points from one coordinate space to another - and defining appropriate transformation definition for that - this is what I remember from my high school math - but don't know how to do that. Is there a way to attach graphics to the messages in this forum?
You can use the HTML 'img' tag to post images (they just have to be hosted somewhere).

Do you know that all roof surfaces will have four corners and be rectangular? Also, do you know what order the corners will be in? (E.g. in order clockwise, in order counterclockwise, etc.)

##### Share on other sites
Quote:
 Original post by jykDo you know that all roof surfaces will have four corners and be rectangular? Also, do you know what order the corners will be in? (E.g. in order clockwise, in order counterclockwise, etc.)
Square roof is a simple case - later there might be roofs with more complex shapes. Would it be easy if the caller provides the origin, x-axis, y-axis, and the actual roof boundary coordinates in 3d? Meanwhile, I will try and create the image to convey graphically.

##### Share on other sites
Quote:
 Square roof is a simple case - later there might be roofs with more complex shapes. Would it be easy if the caller provides the origin, x-axis, y-axis, and the actual roof boundary coordinates in 3d? Meanwhile, I will try and create the image to convey graphically.
You don't necessarily need to get the full orientation from the caller; you could build an arbitrary basis, or build a basis based on the boundary coordinates. (For that matter, you don't necessarily need a position or normal either, since that information can be derived from the boundary coordinates.)

Do you know what order the boundary vertices will be in? Will they be in CW or CCW order? Will they always form a convex polygon, or could they form a simple (possibly non-convex) polygon?

##### Share on other sites
Quote:
 Original post by jykDo you know what order the boundary vertices will be in? Will they be in CW or CCW order? Will they always form a convex polygon, or could they form a simple (possibly non-convex) polygon?

Vertices can be passed in a specific order - or my code can ensure that they are in a specific order - ccw or cw - once received from the caller. Polygon can be convex or concave - there may be holes in too - but for now I want to assume that there are no holes. I agree that if complete roof boundary geometry is passed, then there is no need to pass the normal vector.

##### Share on other sites
Here are the images to further explain.

http://yfrog.com/jlhousewcsp

The image above depicts what I call WCS - World Coordinate System. You will see the axis tripod at the base of the house.

http://yfrog.com/9ehouseroofcsp

The image above depicts what I call RCS - Roof Coordinate System - the axis tripod is now aligned to the roof and the Roof becomes my XY plane.

What I want to accomplish is this: switch to RCS, draw some geometries on the RCS XY plane (where Z=0 in RCS). Then, retrieve the coordinates of the geometries drawn in in RCS, and transform them to WCS (now their Z will no longer be zero).

What is available is the 3D geometry of the actual roof (in WCS) which is rectangular, orientation of the coordinates in expected order (ccw or cw), normal to the roof face and a point on the roof plane.

Thanks!

##### Share on other sites
Hm, I guess I'm not entirely clear on what part you need help with. What you've described is a simple coordinate transform. You create (for example) a 4x4 matrix representing the roof surface's world transform, and then use that matrix to transform geometry from local space to world space as needed.

What math library are you using for this?

##### Share on other sites
Quote:
 Original post by jykHm, I guess I'm not entirely clear on what part you need help with. What you've described is a simple coordinate transform. You create (for example) a 4x4 matrix representing the roof surface's world transform, and then use that matrix to transform geometry from local space to world space as needed.What math library are you using for this?
My main problem is with defining this world transform matrix - how to define it given the roof geometry, etc.

I am not using any specific math library - I have used the vector and matrix routines that I have required so far from the articles in the gamedev.net. Do you recommend any specific library for this purpose?

##### Share on other sites
Quote:
 My main problem is with defining this world transform matrix - how to define it given the roof geometry, etc.
Assuming the input polygon doesn't have any collinear or nearly collinear edges, you can compute the normal by taking the (normalized) cross product of any two consecutive edges.

Once you have the normal, you can compute the next basis vector by normalizing the first edge of the polygon (this is arbitrary, but it seems like a reasonable choice). Once you have two basis vectors, the third can be computed as the cross product of the first two. For the origin of the coordinate system, you can use the first vertex of the polygon.

Once you have the three basis vectors and the position vector, you can load them directly into the rows or columns of a 4x4 matrix (rows for row vectors, columns for column vectors).

Pseudocode (typed into post, so no guarantee of correctness):
vector3 edge1 = vert[1] - vert[0];vector3 edge2 = vert[2] - vert[1];// If the normal ends up pointing the wrong way, reverse the order// of the arguments here:vector3 z = unit_cross(edge1, edge2);vector3 x = normalize(edge1);vector3 y = cross(z, x);vector3 origin = vert[0];// Now load x, y, z, and 'origin' into a 4x4 matrix.
Quote:
 I am not using any specific math library - I have used the vector and matrix routines that I have required so far from the articles in the gamedev.net. Do you recommend any specific library for this purpose?
A good math library will make this a lot easier. What language are you programming in? (I can't remember if you've already mentioned this...)

##### Share on other sites
Quote:
 Original post by jykAssuming the input polygon doesn't have any collinear or nearly collinear edges, you can compute the normal by taking the (normalized) cross product of any two consecutive edges.Once you have the normal, you can compute the next basis vector by normalizing the first edge of the polygon (this is arbitrary, but it seems like a reasonable choice). Once you have two basis vectors, the third can be computed as the cross product of the first two. For the origin of the coordinate system, you can use the first vertex of the polygon.Once you have the three basis vectors and the position vector, you can load them directly into the rows or columns of a 4x4 matrix (rows for row vectors, columns for column vectors).
Yes, this is very helpful - We are setting three axis directions and the origin into the transformation matrix.
Quote:
 A good math library will make this a lot easier. What language are you programming in? (I can't remember if you've already mentioned this...)
This project is in managed Cpp and c# - but I am also proficient in C and Java - should not be a problem to read and understand code in any library you suggest.

##### Share on other sites
Thanks, jyk, with your help I was able to get things done. I appreciate your patient guidance.

##### Share on other sites
Quote:
 Original post by kaarigarThanks, jyk, with your help I was able to get things done. I appreciate your patient guidance.
Great, glad you got it working :)

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627637
• Total Posts
2978335

• 10
• 12
• 22
• 13
• 33