MCPcopy Index your code
hub / github.com/OmkarPathak/pygorithm / project_onto_axis

Method project_onto_axis

pygorithm/geometry/polygon2.py:356–382  ·  view source on GitHub ↗

Find the projection of the polygon along the axis. Uses the `dot product ` of each point on the polygon to project those points onto the axis, and then finds the extremes of the projection. :param p

(polygon, offset, axis)

Source from the content-addressed store, hash-verified

354
355 @staticmethod
356 def project_onto_axis(polygon, offset, axis):
357 """
358 Find the projection of the polygon along the axis.
359
360 Uses the `dot product <https://en.wikipedia.org/wiki/Dot_product>`
361 of each point on the polygon to project those points onto the axis,
362 and then finds the extremes of the projection.
363
364 :param polygon: the polygon to project
365 :type polygon: :class:`pygorithm.geometry.polygon2.Polygon2`
366 :param offset: the offset of the polygon
367 :type offset: :class:`pygorithm.geometry.vector2.Vector2`
368 :param axis: the axis to project onto
369 :type axis: :class:`pygorithm.geometry.vector2.Vector2`
370 :returns: the projection of the polygon along the axis
371 :rtype: :class:`pygorithm.geometry.axisall.AxisAlignedLine`
372 """
373
374 dot_min = None
375 dot_max = None
376 for pt in polygon.points:
377 dot = (pt + offset).dot(axis)
378
379 dot_min = min(dot, dot_min) if dot_min is not None else dot
380 dot_max = max(dot, dot_max) if dot_max is not None else dot
381
382 return axisall.AxisAlignedLine(axis, dot_min, dot_max)
383
384 @staticmethod
385 def contains_point(polygon, offset, point):

Callers 1

find_intersectionMethod · 0.45

Calls 1

dotMethod · 0.80

Tested by

no test coverage detected