Question

Creating a circle through all vertices of a triangle

  • 19 September 2017
  • 7 replies
  • 11 views

Badge

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

Badge

This might help:

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

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

Badge +22

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

Userlevel 2
Badge +17

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))
Badge

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!

 

 

 

Userlevel 4

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.
Badge

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))

Userlevel 4
Badge +13

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