[Closed] Problems Cutting Geometry To Fit Polygon
Ok, this is a long one, but I thought I would explain as much now as I could up front.
I started writing a script with the goal of having it create roof geometry automatically. I thought I had everything working until I found a big problem. The script was written with the assumption that each plane of the roof geometry would be one polygon, but I did not test it beyond simple 4 and 3 sided polygons in the beginning. When I tried a more complex roof shape, I ran into undesired results. Here is the process i am using and the problem I run into…
First I take the polygon, calculate how many rows and columns are needed to cover that surface, and then array the target object on that face and attach them.
Then I slice the attached target object along all the edges of the base polygon. At this point, I was not sure the best way to delete the faces I do not want, so I decided to delete the faces that are on the opposite side of the slice plane as the center of the base polygon is. So whatever side of the edge the center of the base polygon is on, the opposite side is the side that gets faces deleted.
Everything works great when the base polygon is a simple shape. However if I try a more complex shape for the base polygon, problems arise.
Everything works fine until its time to slice the target object.
By slicing the target object along each edge I am slicing through the middle of the object in this case and the results are not what I would like.
This is what I would like to get from this shape.
I have tried to think of a process that could handle more complex shapes and I am stuck. Anyone have any ideas how I can modify my workflow so the script could handle more complex shapes?
If I am not making sense let me know and I can try and clarify… thanks!!
Yea, I don’t get it.
Are you trying to create a roof?
If yes, why is it flat?
What are the teapots for?
And why are you performing a boolean operation on them?
lol… yea i thought it might not make sense. The flat polygon “roof” was just an example of the type of shape that is causing a problem. The angle doesnt matter. The teapots represent the roof tiles, because teapots are faster to model : )
I have the roof geometry already and I am trying to cover it with roof tiles through my script. During testing I used simple geometry and everything worked great, but when I tried it on an actual building model, I came across polygon shapes I had not tested before. Thats when the problems arose. These problems stem from my workflow, I believe, so to fix them I need to change the way I am going about doing things. So I was hoping someone might have some suggestions. I will try to post some other images later to better illustrate the probem.
Well, as you instance tiles across the polygon surface. You can check if a tile is inside a triangle by calculating it’s barycentric coordinate. If the crossproducts are greater then 1.0 then it’s outside the triangle, and if it’s less then 1.0 it’s inside the triangle.
If the crossproducts are greater then 1.0
Sorry, the crossproduct(s) of what?
Of the barycentric coordinate and … ?
Please elaborate.
Thanks.
Georg
lol! Sorry if that wasn’t very clear.
This is a good one for wikipedia!
http://en.wikipedia.org/wiki/Barycentric_coordinates_(mathematics)
The following might be incorrect, because I’m not a mathematics guy!
Barycentric coordinates are very easy to understand once you get it. If you have a 3D triangle, and a 3D point. You project the 3D point onto the plane of the triangle, and then you check to see if that point is inside or outside the triange by calculating it’s barycentric coordinate. I could explain the math, but I’d get it wrong.
So I’ll just give you the darn function!
------------------------------------------------------------------
--
-- returns true if this position is inside the triangle
--
function getBarycentricCoordinates vector1 vector2 vector3 position =
(
area = 0.5 * (length (cross (vector2 - vector1) (vector3 - vector1)))
alpha = 0.5 * (length (cross (vector2 - position) (vector3 - position))) / area
beta = 0.5 * (length (cross (vector1 - position) (vector3 - position))) / area
gamma = 0.5 * (length (cross (vector1 - position) (vector2 - position))) / area
if (abs (1.0 - alpha - beta - gamma )) > 0.00001 do return false
return true
)
Before you call the function you must project the point onto the triangles plane.
example:
-- this is the point you want to check
p = [1,2,3]
for i=1 to obj.numfaces do
(
f = getFace obj i
n = getFaceNormal obj i
v1 = getVert obj f[1]
v2 = getVert obj f[2]
v3 = getVert obj f[3]
-- scalar product projection
nq = dot n (p-v1)
-- continue if backside of triangle
if nq < 0.0f do continue
-- project last node onto triangle plane, e.g. scalar product projection
p0 = p - n * nq
-- compute barycentric coordinates of p0
if (getBarycentricCoordinates v1 v2 v2 p0) do
(
-- this P point is inside the triangle
-- this will tell use how far off the surface p is.
distance = length (p0 - p)
)
)
Buddy, I hope that helps you.
Buddy, I hope that helps you.
Didn’t know about this feature, yet. Thanks for explaining it.
Georg
Thanks for the replys, here are some more images that I hope will help clarify things.
TEST 1
TEST 2
TEST 3 (Problem handing this type of polygon)
So as you can see in test 3, the tiles remaining, are the ones that should be deleted. The problem lies in the way I am deciding which faces to delete. Currently, all i could think of was to take each edge and slice along it. Then delete the faces on the opposite side of the edge as the center of the face. This leads to the problem illustrated above in test 3.
I would like to make the script be able to handle any size or shape polygon, but in order to do so I know my method for slicing and deleting faces needs to be redeveloped. This is what I am having trouble figuring out. A better way of doing that.
I will take a look at the barycentric coordinate method you mentioned Matt. Thanks for the help!
Anyone think of another approach??