How to find center of face

How to find center of face

c_hanschen
Advocate Advocate
4,748 Views
4 Replies
Message 1 of 5

How to find center of face

c_hanschen
Advocate
Advocate

hello,

 

I need the get the normal vector on the center of a face.

 

I already have the geometry, solid and the face, I can get the normal Vector at any point by using face.ComputeNormal, but i need the Centerpoint in UV to use this function.

 

(I mean the UV center laying on the face, not the XYZ centroid)

 

anybody knows how to find this centerpoint in UV?

 

Thanks,

 

Chris Hanschen

The Netherlands

 

 

0 Likes
Accepted solutions (2)
4,749 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

Why do you need the centre to use ComputeNormal?

 

What is your goal with this?

 

What is the centre of a face?

 

Its centre of gravity?

 

Here is one nice little clarification:

 

https://www.mathopenref.com/polygoncenter.html

 

  • Regular Polygon: In the case of regular polygons the center is the point that is equidistant from each vertex or corner. It is also the center of the polygon's incircle and circumcircle.
  • Irregular Polygon: Irregular polygons are not considered as having a center, since there is unlikely to be any one point equally distant form each vertex. However, an irregular polygon can have a centroid, or center of gravity.

 

You can triangulate the face and easily determine a normal for each triangle. 

 

You could determine the centre of gravity of the face borders in UV space and assume that is the centre of the face.

 

Here is a very cool article on a new algorithm for finding a visual center of a polygon:

 

https://blog.mapbox.com/a-new-algorithm-for-finding-a-visual-center-of-a-polygon-7c77e6492fbc

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 5

c_hanschen
Advocate
Advocate

Thanks Jerremy for your respone!

 

I need the most logic angle of a face, relative to the orientation of the Building/Room.

I use the normal vector to calculate the angle projected on the horizontal plane as well as the vertical angle.

This works great for me.

So, when a face is curved, I need the UV coordinates of the center, I agree, a  Irregular Polygon doesn't have a center, than I need the centroid projected to the face (centroid can be outside the face) in UV coordinates.

 

I tried to get all the UV coordinates of the endpoints of the edges of the face, but got an Error.

I managed to get all the edges in XYZ, but not in UV.

 

I will give it another try to get all the edges (start and endpoint) in UV and mathematically calculate the point I need.

 

Thanks for now, I will come back on this topic and share the code I used.

 

Chris Hanschen

The Netherlands

 

 

0 Likes
Message 4 of 5

jeremy_tammik
Alumni
Alumni
Accepted solution

I see no reason why you should get an error determining the UV coordinates of the XYZ edge endpoints.

 

Here is a possible sequence to determine the normal vector in all edge endpoints:

 

 

With that method, you could use the average of all the edge endpoint normals to determine a value for the face normal.

 

The other approach would be to determine some kind of centre point for the face and compute one single normal for that. The problem there might be that the centre point of the face is not actually on the face, for instance, if it has a hole in the middle. Hence the interesting algorithm pointed out above.

 

Using the average of all edge endpoint normals would not have that issue.

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 5 of 5

c_hanschen
Advocate
Advocate
Accepted solution

Thanks Again Jerremy!

 

I know used the function 'TessellateOnFace' on the edges of the face, this worked great for me.

 

Here is my code to find some kind of center by taking the average between min and max in U and V.

 

Public Function GetCenterOfFace(MyFace As Face) As UV

Dim CurvePoints_Umin As Double = Double.MaxValue
Dim CurvePoints_Umax As Double = Double.MinValue
Dim CurvePoints_Vmin As Double = Double.MaxValue
Dim CurvePoints_Vmax As Double = Double.MinValue
Dim EdgePointsUV As New List(Of List(Of UV))
For Each MyEdgeArray As EdgeArray In MyFace.EdgeLoops
For Each MyEdge As Edge In MyEdgeArray
For Each MyUV As UV In MyEdge.TessellateOnFace(MyFace)
CurvePoints_Umin = Math.Min(CurvePoints_Umin, MyUV.U)
CurvePoints_Umax = Math.Max(CurvePoints_Umax, MyUV.U)
CurvePoints_Vmin = Math.Min(CurvePoints_Vmin, MyUV.V)
CurvePoints_Vmax = Math.Max(CurvePoints_Vmax, MyUV.V)
Next

Next
Next

Dim MyCenter As New UV(CurvePoints_Umax - CurvePoints_Umin, CurvePoints_Vmax - CurvePoints_Vmin)

Return MyCenter

End Function

 

Thanks again! 

 

Chris Hanschen

The Netherlands

 

0 Likes