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

Circular Pattern

Here is an example of a circular pattern, separated into two functions: one for the positions and the other for the pattern sketch.

export function generateCircularPatternPositionStructs(radius: number, nrCopies: number, {
  startAngle = 0, endAngle = 2 * Math.PI, referenceAngle = 0, addLast = false } = {}) {
  const positionStructs: { position: SKYMATH.Vector2D, angle: number }[] = []
  const NC = addLast ? nrCopies + 1 : nrCopies
  const angleRange = endAngle - startAngle

  for (let i = 0; i < NC; i++) {
    const angle = angleRange * i / nrCopies + startAngle + referenceAngle
    const position = new SKYMATH.Vector2D(radius * Math.cos(angle), radius * Math.sin(angle))
    positionStructs.push({ position, angle }) // the angle is pushed here so the sketch can be rotated accordingly later
  }
  return positionStructs
}

export function generateCircularPatternSketch(sketchToUseInPattern: SKYSKETCH.Sketch, radius: number, nrCopies: number, {
  startAngle = 0, endAngle = 2 * Math.PI, referenceAngle = 0, addLast = false } = {}) {
  const positionStructs = generateCircularPatternPositionStructs(radius, nrCopies, { startAngle, endAngle, referenceAngle, addLast })
  const circularPatternSketch = new SKYSKETCH.Sketch()

  positionStructs.forEach(struct => {
    const { position, angle } = struct
    const patternSketch = sketchToUseInPattern.clone()
    patternSketch.scale(radius / 30) // scale sketch according to radius
    patternSketch.rotate(angle) // point inwards
    patternSketch.translate(position.x, position.y)
    circularPatternSketch.mergeSketch(patternSketch)
  })

  return circularPatternSketch
}
← IntroductionRectangular Pattern →
DynaMaker Docs
Docs
Getting StartedTrainingLibrary
Community
LoginExamplesLinkedIn
More
HomepageBlogNews
Copyright © 2021 Skymaker AB