Polygon

Core::Diagram::Polygon

Overview

Concrete Class

A figure that is delimited by a closed chain of three or more straight sections.

(Fullscreen Diagram)

GraphicalElementGraphicalPrimitivePolygonFillStyle :FillStylePoints :Point [3..*] {ordered}Stroke :Stroke

Supertypes

Members

Data Properties

Name

Multiplicity

Type

Ordered

Unique

FillStyle

1

FillStyle

no

no

The fill style of the Polygon.

Points

3..*

Point

yes

no

The points (vertices) of the Polygon.

Stroke

1

Stroke

no

no

The stroke of the Polygon.

Geometry

The first straight section that delimits a Polygon starts at its first Point, i.e., Points[0], and ends at its second Point. For each further Point, another section is added that starts at the preceding Point. Finally, a section is added that starts at the last Point and goes back to the first Point such that the chain of sections is closed.

Example

We consider a Polygon with 4 Points:

  • (-30, 40),

  • (50, 40),

  • (-10, -60), and

  • (-10, 0).

The Polygon will look like this:

../../../_images/img9.svg

Interior of a Polygon

Depending on its FillStyle, the interior of a Polygon may be filled. There are several possibilities to define when “a point is inside a polygon”. DEXPI applies a simple intuitive rule:

  • Choose an arbitrary point outside the geometric bounding box of the Polygon.

  • Each point that can be reached from there without crossing any segment is outside the Polygon.

  • Each other point is inside the Polygon.

Example

The grey area in the figure visualizes the interior of the given Polygon.

../../../_images/img10.svg

Technical

In case of polygons, the DEXPI definition for interior points coincides with the nonzero rule in SVG. See Section 13.4.2. of the SVG 2 Recommendation for a more precise definition of the nonzero rule.

The SVG 2 Recommendation also defines an alternative rule called evenodd rule. If we applied this rule, the pentagonal area in the center of this Polygon would be considered outside:

../../../_images/img11.svg

Visual Center

Let \(n\) be the number of Points, and let \(x_i\) and \(y_i\) be the X and Y positions of Point \(i\) for \(0 \leq i < n\).

Then the horizontal position \(c_x\) and the vertical position \(c_y\) of the visual center of the Polygon are

\[ \begin{align}\begin{aligned}c_x &= \frac 1 2 \Big[ \min_{i=0}^{n-1} x_i + \max_{i=0}^{n-1} x_i \Big] \quad ,\\c_y &= \frac 1 2 \Big[ \min_{i=0}^{n-1} y_i + \max_{i=0}^{n-1} y_i \Big] \quad .\end{aligned}\end{align} \]

Intuitively, the visual center is the center of the minimum bounding box that contains all Points.

If the Polygon has the FillStyle Hatch, then one of the hatch lines will cross through the visual center.

Example

For the Polygon above, we have

\[ \begin{align}\begin{aligned}c_x &= \frac 1 2 [ \min(-30, 50, -10, -10) + \max(-30, 50, -10, -10) ]\\ &= \frac 1 2 [-30 + 50]\\ &= 10\end{aligned}\end{align} \]

and

\[ \begin{align}\begin{aligned}c_y &= \frac 1 2 [ \min(40, 40, -60, 0) + \max(40, 40, -60, 0) ]\\ &= \frac 1 2 [-60 + 40]\\ &= -10 \quad .\end{aligned}\end{align} \]

Mapping to SVG

A Polygon corresponds to an svg:polygon with these attributes:

  • transform contains a translation from the origin to the visual center. This is required due to the modified positions in points.

    transform = "translate( + str(\(c_x\)) + , + str(\(c_y\)) + )"

  • points contains the Points of the Polygon relative to the visual center.

    For each Point \(i\) with (absolute) position \(x_i\) and \(y_i\), the position relative to the visual center is

    \[ \begin{align}\begin{aligned}\tilde{x}_i &= x_i - c_x \quad ,\\\tilde{y}_i &= y_i - c_y \quad .\end{aligned}\end{align} \]

    Each of the relative positions is converted to a string as str(\(\tilde{x}_i\)) + , + str(\(\tilde{y}_i\)). Finally, the points attribute is set to a single string that contains all relative positions, separated by spaces.

  • stroke, stroke-dasharray, stroke-dashoffset and stroke-width are set according to the SVG mapping rules for the Stroke of the Polygon (see Stroke).

  • stroke-linecap = "round" and stroke-linejoin = "round" reflect the heuristic for line caps and line joins.

  • vector-effect = "non-scaling-stroke" reflects the heuristic for scaled symbols.

  • fill is set according to the SVG mapping rules for the FillStyle of the Polygon (see FillStyle).

Example

We assume that the Stroke of the Polygon above is 2mm #ff00ff Solid and that its FillStyle is Transparent.

{PolygonTransparentSvgCode}
../../../_images/img12.svg

Example

We consider the same Polygon as in the previous example, except that the Stroke is 2mm #ff00ff Dot.

{PolygonDotSvgCode}
../../../_images/img13.svg

Example

Finally, a variant with Stroke 2mm #ff00ff Solid and FillStyle Hatch.

{PolygonHatchSvgCode}
../../../_images/img14.svg

FillStyle

Data Property

The fill style of the Polygon.

Type: FillStyle

Multiplicity: 1

Ordered: no

Unique: no

Example

Transparent

Points

Data Property

The points (vertices) of the Polygon.

Type: Point

Multiplicity: 3..*

Ordered: yes

Unique: no

Example

[

     Point(

          X = 3.5,

          Y = 5.5),

     Point(

          X = 5.5,

          Y = 7.5),

     Point(

          X = 1.5,

          Y = 9.5)

]

Stroke

Data Property

The stroke of the Polygon.

Type: Stroke

Multiplicity: 1

Ordered: no

Unique: no

Example

Stroke(

     Color = Color(

          B = 0,

          G = 0,

          R = 128),

     DashStyle = Solid,

     Width = 0.3)

Example in DEXPI XML

<Object type="Core/Diagram.Polygon">
  <Data property="FillStyle">
    <DataReference data="Core/Diagram.FillStyle.Transparent"/>
  </Data>
  <Data property="Points">
    <AggregatedDataValue type="Core/Diagram.Point">
      <Data property="X">
        <Double>3.5</Double>
      </Data>
      <Data property="Y">
        <Double>5.5</Double>
      </Data>
    </AggregatedDataValue>
    <AggregatedDataValue type="Core/Diagram.Point">
      <Data property="X">
        <Double>5.5</Double>
      </Data>
      <Data property="Y">
        <Double>7.5</Double>
      </Data>
    </AggregatedDataValue>
    <AggregatedDataValue type="Core/Diagram.Point">
      <Data property="X">
        <Double>1.5</Double>
      </Data>
      <Data property="Y">
        <Double>9.5</Double>
      </Data>
    </AggregatedDataValue>
  </Data>
  <Data property="Stroke">
    <AggregatedDataValue type="Core/Diagram.Stroke">
      <Data property="Color">
        <AggregatedDataValue type="Core/Diagram.Color">
          <Data property="B">
            <Integer>0</Integer>
          </Data>
          <Data property="G">
            <Integer>0</Integer>
          </Data>
          <Data property="R">
            <Integer>128</Integer>
          </Data>
        </AggregatedDataValue>
      </Data>
      <Data property="DashStyle">
        <DataReference data="Core/Diagram.DashStyle.Solid"/>
      </Data>
      <Data property="Width">
        <Double>0.3</Double>
      </Data>
    </AggregatedDataValue>
  </Data>
</Object>