Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Transform sketch entities

graham_lock
graham_lock Member Posts: 276 PRO

Hi,

I've been unsuccessful in finding an example of transforming sketch entities.

In my use case I need to rotate a rectangle about its centre.

So far I have:

skRectangle(sketchStartFormer, "rectangleStartFormer", {
"firstCorner" : vector(centreStartXmm - (width / 2), centreStartYmm - (height / 2)),
"secondCorner" : vector(centreStartXmm + (width / 2), centreStartYmm + (height / 2))
});

const rotationMatrix = [[cos(startRotation), -sin(startRotation)], [sin(startRotation), cos(startRotation)]] as Matrix;

How do I apply this (if it's correct) to the rectangle and rotate it about its center?

Thank you.

Best Answer

  • Caden_Armstrong
    Caden_Armstrong Member Posts: 458 PRO
    Answer ✓

    You have a few different options,

    - Calculate the four corners and create 4 line segments (this is how onshape does aligned rectangles, probably how I would do it in this case).


    - Create rectangle, solve the sketch, and use opTransform to rotate it, just note that opTransform takes in a transform not a matrix.


    - Create the rectangle and use sketch constraints to rotate it (personally my least favourite option)

    www.smartbenchsoftware.com --- Renaissance --- Kestrel -- SmartLink
    Experts in Onshape Automation - Custom Features and Integrated Applications

Answers

  • Caden_Armstrong
    Caden_Armstrong Member Posts: 458 PRO
    Answer ✓

    You have a few different options,

    - Calculate the four corners and create 4 line segments (this is how onshape does aligned rectangles, probably how I would do it in this case).


    - Create rectangle, solve the sketch, and use opTransform to rotate it, just note that opTransform takes in a transform not a matrix.


    - Create the rectangle and use sketch constraints to rotate it (personally my least favourite option)

    www.smartbenchsoftware.com --- Renaissance --- Kestrel -- SmartLink
    Experts in Onshape Automation - Custom Features and Integrated Applications
  • graham_lock
    graham_lock Member Posts: 276 PRO

    Thank you