<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: [Bug?] pointOnFace in rare cases returns a point at a corner of the face in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bug-pointonface-in-rare-cases-returns-a-point-at-a-corner-of-the/m-p/10439492#M8528</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3787950"&gt;@kandennti&lt;/a&gt;&amp;nbsp;, Thank you for your reply and your code. Actually after finding the rare case issue, I used the almost same method in my code based on &lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/checking-whether-a-2d-point-lies-within-a-flat-surface-profile/td-p/6283308" target="_blank" rel="noopener"&gt;this post&lt;/A&gt;&amp;nbsp;without even using face.pointOnFace. I think based on its random nature it is almost impossible that this method to return a point on an edge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my opinion it is a bug. I think the whole point of face.pointOnFace is to return a point which is &lt;SPAN&gt;guaranteed to be within the face's boundaries (not on the boundary) because the boundary conditions causes problems in many algorithms (for example offsetting the edges inward or outward). If we want to find a point on a face and we do not care if it is on an edge or not, we can just use a point on edge or corner and easily find it.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Jul 2021 19:32:20 GMT</pubDate>
    <dc:creator>nnikbin</dc:creator>
    <dc:date>2021-07-02T19:32:20Z</dc:date>
    <item>
      <title>[Bug?] pointOnFace in rare cases returns a point at a corner of the face</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bug-pointonface-in-rare-cases-returns-a-point-at-a-corner-of-the/m-p/10434443#M8526</link>
      <description>&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-96c6af33-7a7f-433e-b630-7e264ff59b91" target="_blank" rel="noopener"&gt;BRepFace.pointOnFace&lt;/A&gt; in some rare cases returns a point at a corner of the face. For example it returns (40, 40, 0) for the following face. The related file is attached.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="54.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/936422iDE943BD42325C1FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="54.png" alt="54.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It seems to be&amp;nbsp;in contrast to what is promised in the relevant document:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Returns a sample point &lt;STRONG&gt;guaranteed&lt;/STRONG&gt; to lie on the face's surface, within the face's boundaries, and &lt;STRONG&gt;not on a boundary edge&lt;/STRONG&gt;.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It may not seem a big deal but for an add-in which depends on the accuracy of this property it could mean the potential for wrong functionality.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 04:12:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bug-pointonface-in-rare-cases-returns-a-point-at-a-corner-of-the/m-p/10434443#M8526</guid>
      <dc:creator>nnikbin</dc:creator>
      <dc:date>2021-07-01T04:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: [Bug?] pointOnFace in rare cases returns a point at a corner of the face</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bug-pointonface-in-rare-cases-returns-a-point-at-a-corner-of-the/m-p/10435927#M8527</link>
      <description>&lt;P&gt;HI &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2799701"&gt;@nnikbin&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm sorry, but I don't see this as a bug.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At least the "Shape Manager" seems to consider a point on an edge to be on a surface.&lt;BR /&gt;You can check this by using the isParameterOnFace method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-e6682eb7-48f8-472d-9872-71da3c5ba8c8" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-e6682eb7-48f8-472d-9872-71da3c5ba8c8&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script
import adsk.core, adsk.fusion, traceback

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app :adsk.fusion.Application = adsk.core.Application.get()
        ui = app.userInterface
        des :adsk.fusion.Design = app.activeProduct
        root :adsk.fusion.Component = des.rootComponent

        face :adsk.fusion.BRepFace = root.bRepBodies[0].faces[0]
        pointOnFace :adsk.core.Point3D = face.pointOnFace
        eva :adsk.core.SurfaceEvaluator = face.evaluator
        _, prm = eva.getParameterAtPoint(pointOnFace)

        ui.messageBox(f'{eva.isParameterOnFace(prm)}')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is not convenient on the edge, I think there is no other way but to create such a mechanism, so I made one.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script
import adsk.core, adsk.fusion, traceback
import random

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app :adsk.fusion.Application = adsk.core.Application.get()
        ui = app.userInterface
        des :adsk.fusion.Design = app.activeProduct
        root :adsk.fusion.Component = des.rootComponent

        # Point On Face
        face :adsk.fusion.BRepFace = root.bRepBodies[0].faces[0]
        pointOnFace :adsk.core.Point3D = face.pointOnFace
        dumpPoint(pointOnFace, root, 'Point On Face')

        # Point On Face  Exclude On The Edge
        for _ in range(10):
            excludeOnEdge = getPointOnFace_ExcludeOnEdge(face)
            dumpPoint(excludeOnEdge, root, 'Exclude On The Edge')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def getPointOnFace_ExcludeOnEdge(
    face :adsk.fusion.BRepFace) -&amp;gt; adsk.core.Point3D:

    def getUniqueParameter(
        minPrm :adsk.core.Point2D,
        maxPrm :adsk.core.Point2D) -&amp;gt; adsk.core.Point2D:

        return adsk.core.Point2D.create(
            random.uniform(minPrm.x, maxPrm.x),
            random.uniform(minPrm.y, maxPrm.y))

    def isPointOnEdges(
        pnt :adsk.core.Point3D,
        toleranceEdgeDistance :float = 0.1) -&amp;gt; bool:

        for edge in face.edges:
            if isPointOnEdge(pnt, edge, toleranceEdgeDistance):
                return True

        return False

    def isPointOnEdge(
        pnt :adsk.core.Point3D,
        edge :adsk.fusion.BRepEdge,
        toleranceEdgeDistance :float) -&amp;gt; bool:

        eva :adsk.core.CurveEvaluator3D = edge.evaluator
        _, prm = eva.getParameterAtPoint(pnt)

        _, prmPnt = eva.getPointAtParameter(prm)
        return pnt.isEqualToByTolerance(prmPnt, toleranceEdgeDistance)

    # ***

    pnt :adsk.core.Point3D = face.pointOnFace
    if not isPointOnEdges(pnt):
        return pnt

    surfEva :adsk.core.SurfaceEvaluator = face.evaluator
    bound :adsk.core.BoundingBox2D = surfEva.parametricRange()

    while True:
        prm = getUniqueParameter(bound.minPoint, bound.maxPoint)

        if not surfEva.isParameterOnFace(prm):
            continue

        _, pnt = surfEva.getPointAtParameter(prm)

        if not isPointOnEdges(pnt):
            return pnt


def dumpPoint(
    pnt :adsk.core.Point3D,
    comp :adsk.fusion.Component,
    name :str):

    skt :adsk.fusion.Sketch = comp.sketches.add(comp.xYConstructionPlane)
    skt.name = name
    skt.sketchPoints.add(pnt)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since it can be done in a random position, the result will change every time you run it.&lt;BR /&gt;There may be a better algorithm.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 14:41:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bug-pointonface-in-rare-cases-returns-a-point-at-a-corner-of-the/m-p/10435927#M8527</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2021-07-01T14:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: [Bug?] pointOnFace in rare cases returns a point at a corner of the face</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bug-pointonface-in-rare-cases-returns-a-point-at-a-corner-of-the/m-p/10439492#M8528</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3787950"&gt;@kandennti&lt;/a&gt;&amp;nbsp;, Thank you for your reply and your code. Actually after finding the rare case issue, I used the almost same method in my code based on &lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/checking-whether-a-2d-point-lies-within-a-flat-surface-profile/td-p/6283308" target="_blank" rel="noopener"&gt;this post&lt;/A&gt;&amp;nbsp;without even using face.pointOnFace. I think based on its random nature it is almost impossible that this method to return a point on an edge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my opinion it is a bug. I think the whole point of face.pointOnFace is to return a point which is &lt;SPAN&gt;guaranteed to be within the face's boundaries (not on the boundary) because the boundary conditions causes problems in many algorithms (for example offsetting the edges inward or outward). If we want to find a point on a face and we do not care if it is on an edge or not, we can just use a point on edge or corner and easily find it.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jul 2021 19:32:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/bug-pointonface-in-rare-cases-returns-a-point-at-a-corner-of-the/m-p/10439492#M8528</guid>
      <dc:creator>nnikbin</dc:creator>
      <dc:date>2021-07-02T19:32:20Z</dc:date>
    </item>
  </channel>
</rss>

