DynaMaker Docs

DynaMaker Docs

  • dynamaker.com
  • Account

›Snippets

Getting Started

  • Introduction
  • Dashboard
  • Before You Code

Training

  • Introduction
  • Tutorials

    • My First App
    • My First Drawing
    • My First Assembly
    • Presets, Test & Debug
    • User Interface
    • Factories

    How To

    • Download Files
    • Save & Load
    • Add Textures

Snippets

  • Introduction
  • Circular Pattern
  • Rectangular Pattern

Integration

  • Embedding
  • REST APIs
  • Quotations
  • Webhooks

Library

  • Introduction
  • SKYMATH
  • SKYSKETCH
  • SKYCAD
  • SKYPARAM
  • SKYUI
  • SKYDRAWING
  • PRESET
  • SKYEXPORT_POLY
  • STUDIO

Other

  • Changes 2021-02-17
  • Changes 2020-10-20
  • Did You Know...
  • FAQ

Rectangular Pattern

There are many ways to define a rectangular pattern, the following are some examples based on the number of copies or the size-dependent variables. In both cases the pattern is separated into two functions: one for the positions and the other for the pattern sketch.

Number Of Copies

function getPatternPositions(nrCopiesVector: SKYMATH.Vector2D, distanceVector: SKYMATH.Vector2D) {
  const positions = []
  for (let i = 0; i < nrCopiesVector.x; i++) {
    for (let j = 0; j < nrCopiesVector.y; j++) {
      const position = new SKYMATH.Vector2D(i * distanceVector.x, j * distanceVector.y)
      positions.push(position)
    }
  }
  return positions
}

export function generateRectangularPatternSketch(sketchToUseInPattern: SKYSKETCH.Sketch, nrCopiesVector: SKYMATH.Vector2D, distanceVector: SKYMATH.Vector2D) {
  const patternSketch = new SKYSKETCH.Sketch()
  const patternPositions = getPatternPositions(nrCopiesVector, distanceVector)
  patternPositions.forEach(position => {
    const clonedSketch = sketchToUseInPattern.clone()
    clonedSketch.translate(position.x, position.y)
    patternSketch.mergeSketch(clonedSketch)
  })
  return patternSketch
}

Size

export function getPatternPositions(lengthVector: SKYMATH.Vector2D, distanceBetweenVector: SKYMATH.Vector2D, holeSize: number, autocentered: boolean) {
  const nrCopiesX = Math.floor(lengthVector.x / (holeSize + distanceBetweenVector.x))
  const nrCopiesY = Math.floor(lengthVector.y / (holeSize + distanceBetweenVector.y))
  const nrCopiesVector = new SKYMATH.Vector2D(nrCopiesX, nrCopiesY)

  const startOffset = (autocentered)
    ? new SKYMATH.Vector2D(
      (lengthVector.x - nrCopiesX * holeSize - (nrCopiesX - 1) * distanceBetweenVector.x) / 2,
      (lengthVector.y - nrCopiesY * holeSize - (nrCopiesY - 1) * distanceBetweenVector.y) / 2,
    )
    : new SKYMATH.Vector2D(0, 0)

  const positions = []
  for (let i = 0; i < nrCopiesVector.x; i++) {
    for (let j = 0; j < nrCopiesVector.y; j++) {
      const position = new SKYMATH.Vector2D(startOffset.x + i * (holeSize + distanceBetweenVector.x), startOffset.y + j * (holeSize + distanceBetweenVector.y))
      positions.push(position)
    }
  }
  return positions
}

export function generateRectangularPatternSketch(sketchToUseInPattern: SKYSKETCH.Sketch, lengthVector: SKYMATH.Vector2D, distanceBetweenVector: SKYMATH.Vector2D, holeSize: number, autocentered: boolean) {
  const patternSketch = new SKYSKETCH.Sketch()
  const patternPositions = getPatternPositions(lengthVector, distanceBetweenVector, holeSize, autocentered)
  patternPositions.forEach(position => {
    const clonedSketch = sketchToUseInPattern.clone()
    clonedSketch.translate(position.x, position.y)
    patternSketch.mergeSketch(clonedSketch)
  })
  return patternSketch
}

← Circular PatternEmbedding →
  • Number Of Copies
  • Size
DynaMaker Docs
Docs
Getting StartedTrainingLibrary
Community
LoginExamplesLinkedIn
More
HomepageBlogNews
Copyright © 2021 Skymaker AB