Skip to content
This repository was archived by the owner on Sep 25, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions components/geometry/base/geom_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import suit.cf.utils as comutils
import suit.core.render.engine as render_engine
import geom_controls
import math

class GeometryEditMode(BaseEditMode):

Expand Down Expand Up @@ -357,6 +358,58 @@ def _onKeyPressed(self, _evt):
if isinstance(obj, (GeometryTriangle, GeometryQuadrangle)):
self.state = GeometryEditMode.ES_PerimeterChange
self.perimetr_changer = TextInput(obj, self._perimeter_change_callback, obj.getPropertyValue(GeometryAbstractObject.PropPerimeter))

if key == ois.KC_O:
selected = self._logic._getSheet().getSelected()
for obj in selected:
if isinstance(obj, (GeometryTriangle)):

triangleSides = obj.getSides()

circumcirclePoints = obj._calculateCircumcirclePoints()

# create center point of circle
centerPointCoord = circumcirclePoints[0]
center = self._logic.createPoint(centerPointCoord)
sheet = self._logic._getSheet()
sheet.addChild(center)
center._updateView()

vertexA_x = render_engine.pos3dTo2dWindow(triangleSides[0].getEnd().getPosition())[0]
vertexA_y = render_engine.pos3dTo2dWindow(triangleSides[0].getEnd().getPosition())[1]
vertexB_x = render_engine.pos3dTo2dWindow(triangleSides[1].getEnd().getPosition())[0]
vertexB_y = render_engine.pos3dTo2dWindow(triangleSides[1].getEnd().getPosition())[1]
vertexC_x = render_engine.pos3dTo2dWindow(triangleSides[2].getEnd().getPosition())[0]
vertexC_y = render_engine.pos3dTo2dWindow(triangleSides[2].getEnd().getPosition())[1]

vertexPointCoordA = vertexA_x, vertexA_y
vertexPointCoordB = vertexB_x, vertexB_y
vertexPointCoordC = vertexC_x, vertexC_y

sideObjects = self._logic._getSheet()._getObjectsUnderMouse(True, True, vertexPointCoordA)
vertexA = comutils._getFirstObjectTypeFromList(sideObjects, [GeometryPoint])

sideObjects = self._logic._getSheet()._getObjectsUnderMouse(True, True, vertexPointCoordB)
vertexB = comutils._getFirstObjectTypeFromList(sideObjects, [GeometryPoint])

sideObjects = self._logic._getSheet()._getObjectsUnderMouse(True, True, vertexPointCoordC)
vertexC = comutils._getFirstObjectTypeFromList(sideObjects, [GeometryPoint])

_selected = center, vertexA

obj._setCircumcirclePoints(_selected)


#draw circumcircle
self.active_object = self._logic.createCircle()

if self.active_object.makeBasedOnObjects(_selected):
self._logic._getSheet().addChild(self.active_object)
else:
self.active_object.delete()
self.active_object.addPoint(vertexB, self.active_object._calculatePointRelPosition(render_engine.pos2dTo3dIsoPos(vertexPointCoordB)))
self.active_object.addPoint(vertexC, self.active_object._calculatePointRelPosition(render_engine.pos2dTo3dIsoPos(vertexPointCoordC)))
self.active_object = None

return False

Expand Down
50 changes: 50 additions & 0 deletions components/geometry/base/geom_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,8 @@ def __init__(self):
self.__manualObject = None # manual object to store and render geometry
self.pts = [] # triangle vertex points
self.sides = [] # triangle sides
self.isCircumcircleDrawed = False #flag showing is circumcircle shown on objects sheet
self.circumcirclePoints = [] #turple for circumcircle points

def __del__(self):
suit.core.objects.ObjectDepth.__del__(self)
Expand Down Expand Up @@ -985,6 +987,15 @@ def _update(self, _timeSinceLastFrame):

self.__manualObject.end()

# update circumcircle points position
if self.isCircumcircleDrawed:
circumcirclePointsCoordinates = self._calculateCircumcirclePoints()
circumcircle = self.circumcirclePoints[0]
vertex = self.circumcirclePoints[1]
circumcircle.setPosition(render_engine.pos2dTo3dIsoPos(circumcirclePointsCoordinates[0]))
vertex.setPosition(render_engine.pos2dTo3dIsoPos(circumcirclePointsCoordinates[1]))


suit.core.objects.ObjectDepth._update(self, _timeSinceLastFrame)

def _updateView(self):
Expand Down Expand Up @@ -1119,6 +1130,45 @@ def build_text_idtf(self):
else:
return None

def _calculateCircumcirclePoints(self):
"""Calculate points for circumcircle and draw it on objects sheet
"""
# calculate triangle vertex coordinates
pointA_x = render_engine.pos3dTo2dWindow(self.pts[0].getPosition())[0]
pointA_y = render_engine.pos3dTo2dWindow(self.pts[0].getPosition())[1]
pointB_x = render_engine.pos3dTo2dWindow(self.pts[1].getPosition())[0]
pointB_y = render_engine.pos3dTo2dWindow(self.pts[1].getPosition())[1]
pointC_x = render_engine.pos3dTo2dWindow(self.pts[2].getPosition())[0]
pointC_y = render_engine.pos3dTo2dWindow(self.pts[2].getPosition())[1]

# calculate center coordinates
coefficient_A1 = 2*(pointB_x-pointA_x)
coefficient_A2 = 2*(pointC_x-pointB_x)
coefficient_B1 = 2*(pointB_y-pointA_y)
coefficient_B2 = 2*(pointC_y-pointB_y)
coefficient_C1 = math.pow(pointB_x, 2)-math.pow(pointA_x,2)+math.pow(pointB_y, 2)-math.pow(pointA_y,2)
coefficient_C2 = math.pow(pointC_x, 2)-math.pow(pointB_x,2)+math.pow(pointC_y, 2)-math.pow(pointB_y,2)

center_y = (coefficient_C2*coefficient_A1-coefficient_A2*coefficient_C1)/(coefficient_B2*coefficient_A1-coefficient_A2*coefficient_B1)
center_x = (coefficient_C1-coefficient_B1*center_y)/coefficient_A1

# create center point
centerPointCoord = center_x, center_y

# create vertex point
vertexPointCoord = pointA_x, pointA_y

return [centerPointCoord, vertexPointCoord]

def _setCircumcirclePoints(self, circumcirclePoints):
"""set list of circumcircle points
"""
self.circumcirclePoints = circumcirclePoints

def _getCircumcirclePoints(self):
"""get list of circumcircle points
"""
return self.circumcirclePoints

class GeometryQuadrangle(suit.core.objects.ObjectDepth, GeometryAbstractObject):

Expand Down