Geometry construction on an inclined plane

Started by
19 comments, last by Zakwayda 13 years, 5 months ago
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.)
Advertisement
Quote:Original post by jyk
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.)
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.
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?
Quote:Original post by jyk
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?

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.

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.

I hope I have made this explanation clear enough - can someone please help me out?

Thanks!
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?
Quote:Original post by jyk
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?
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?

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...)
Quote:Original post by jyk
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).
<snip>
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.

Thanks, jyk, with your help I was able to get things done. I appreciate your patient guidance.

This topic is closed to new replies.

Advertisement