FS calculating plane normal

graham_lock
graham_lock Member Posts: 277 PRO
Hi,

I'm creating a plane at an offset from a reference plane which I also want to angle at a given number of degrees.

My test code looks like this:

const p is Plane = plane(
                offsetDirection ? (refPlane.origin - (offset * refPlane.normal)) : (refPlane.origin + (offset * refPlane.normal)),
                vector(0, 0.1, 0.3)
                );


            opPlane(context, id + "plane1", {
                        "plane" : p
                    });

How should I go about generating the normal vector to achieve the desired angle?

Thank you.

Best Answer

  • Caden_Armstrong
    Caden_Armstrong Member Posts: 472 PRO
    Answer ✓
    FeatureScript transforms are great, they do a lot of heavy lifting for you.

    If you create a rotation transform:
    var rotationangle = rotationAround(X_AXIS, 30*degree);
    var newVector = rotationangle*oldvector;
    The one thing is that it only works with vectors that have a length.
    So you'll need to take  your normal, give it units (ie oldvector*meter), rotate it, and then remove units (newVector/meter)

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

Answers

  • Caden_Armstrong
    Caden_Armstrong Member Posts: 472 PRO
    Answer ✓
    FeatureScript transforms are great, they do a lot of heavy lifting for you.

    If you create a rotation transform:
    var rotationangle = rotationAround(X_AXIS, 30*degree);
    var newVector = rotationangle*oldvector;
    The one thing is that it only works with vectors that have a length.
    So you'll need to take  your normal, give it units (ie oldvector*meter), rotate it, and then remove units (newVector/meter)

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