Skip to main content
Question

Creating a circle through all vertices of a triangle

  • September 19, 2017
  • 7 replies
  • 70 views

Forum|alt.badge.img

Hi All,

How would I go about creating a circle where the perimeter passes through all three vertices of a triangle?

I've attempted to use the Minimum Spanning Circle Replacer, but this creates a circle based only on the longest side of the triangle.

Any ideas would be greatly appreciated.

Thanks

7 replies

Forum|alt.badge.img

This might help:

http://paulbourke.net/geometry/circlesphere/

Scroll down to "Equation of a Circle from 3 Points"


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • September 19, 2017

Edit: This deals with the edge cases where two points are aligned vertically, two or more points are coincident and if there is anything other than 3 points

 

 

circlefrom3points.fmw


takashi
Influencer
  • September 20, 2017

I would try this with a PythonCaller.

# PythonCaller Script Example
# Replace feature's geometry with a circle created from its first three vertices.
# Assume the input feature has a geometry having three or more vertices.
# The three vertices should have different coordinates, and any one of them
# should not be on the straight line passing other two vertices.
import fmeobjects
def createCircleFromThreeVertices(feature):
    coords = feature.getAllCoordinates()
    threeVertices = [fmeobjects.FMEPoint(*p) for p in coords[:3]]
    arc = fmeobjects.FMEArc(tuple(threeVertices))
    arc.setSweepAngle(360)
    feature.setGeometry(fmeobjects.FMEEllipse(arc))

Forum|alt.badge.img
  • Author
  • September 20, 2017
jdh wrote:

Edit: This deals with the edge cases where two points are aligned vertically, two or more points are coincident and if there is anything other than 3 points

 

 

circlefrom3points.fmw

This worked perfectly, thank you!

 

 

 


david_r
Celebrity
  • September 20, 2017
takashi wrote:

I would try this with a PythonCaller.

# PythonCaller Script Example
# Replace feature's geometry with a circle created from its first three vertices.
# Assume the input feature has a geometry having three or more vertices.
# The three vertices should have different coordinates, and any one of them
# should not be on the straight line passing other two vertices.
import fmeobjects
def createCircleFromThreeVertices(feature):
    coords = feature.getAllCoordinates()
    threeVertices = [fmeobjects.FMEPoint(*p) for p in coords[:3]]
    arc = fmeobjects.FMEArc(tuple(threeVertices))
    arc.setSweepAngle(360)
    feature.setGeometry(fmeobjects.FMEEllipse(arc))
Elegant and minimal, I like it. The PythonCaller might also be followed by an ArcStroker if the destination doesn't support arcs.

Forum|alt.badge.img
  • May 10, 2019
takashi wrote:

I would try this with a PythonCaller.

# PythonCaller Script Example
# Replace feature's geometry with a circle created from its first three vertices.
# Assume the input feature has a geometry having three or more vertices.
# The three vertices should have different coordinates, and any one of them
# should not be on the straight line passing other two vertices.
import fmeobjects
def createCircleFromThreeVertices(feature):
    coords = feature.getAllCoordinates()
    threeVertices = [fmeobjects.FMEPoint(*p) for p in coords[:3]]
    arc = fmeobjects.FMEArc(tuple(threeVertices))
    arc.setSweepAngle(360)
    feature.setGeometry(fmeobjects.FMEEllipse(arc))

This worked great for generating closed arcs (circles) but in attempting to output arcs with a start/end point and changing the sweep angle value it always returns a closed arc having the same start/end point.  Its as if the arc.setSweepAngle(x) statement is ignored?  What am I missing?

import fmeobjects

def createArcFromTwoVertices(feature):

    coords = feature.getAllCoordinates()

    twoVertices = [fmeobjects.FMEPoint(*p) for p in coords[:2]]

    arc = fmeobjects.FMEArc(tuple(twoVertices),rad,False)

    arc.setSweepAngle(sweep_angle)

    feature.setGeometry(fmeobjects.FMEEllipse(arc))


fmelizard
Contributor
Forum|alt.badge.img+17
  • Contributor
  • May 15, 2019
wallace wrote:

This worked great for generating closed arcs (circles) but in attempting to output arcs with a start/end point and changing the sweep angle value it always returns a closed arc having the same start/end point.  Its as if the arc.setSweepAngle(x) statement is ignored?  What am I missing?

import fmeobjects

def createArcFromTwoVertices(feature):

    coords = feature.getAllCoordinates()

    twoVertices = [fmeobjects.FMEPoint(*p) for p in coords[:2]]

    arc = fmeobjects.FMEArc(tuple(twoVertices),rad,False)

    arc.setSweepAngle(sweep_angle)

    feature.setGeometry(fmeobjects.FMEEllipse(arc))

Hi @wallace You can create an Arc by 3 Points without Python, using an FMEFunctionCaller:

@Geometry(SET_PROPERTIES, ARC3POINTS,
      [<startX>], [<startY>], [<startZ>],
      [<midX>], [<midY>], [<midZ>],
      [<endX>], [<endY>], [<endZ>])

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings