Jump to content
konstantin magnus

Multiply vectors to a plane (Trigonometry questions)

Recommended Posts

Posted (edited)

Hi, I was shaping a hex nut with VEX when two geometry questions arose:

hex_nut.png.278b238ee3e6c3614684810fe3c3cf01.png

  • How can I mathematically define the offset from a circle to an n-gon? Currently I am multiplying by a magic number: sin(u_mod) * 0.12.
  • How can I multiply vectors so they end up on an infinite plane defined by a position and a normal? Kind of what planepointdistance() does, but rather intersecting the plane with the points vector than just returning the closest position on the plane. Also I would not want to shoot rays around but rather set this mathematically.

Here is how I deform the tubes outer points at the moment:

float u = atan(v@P.z, v@P.x);
float u_mod = abs(sin(u * 3));
float u_fit = fit01(u_mod, 0.75, 1.0);

vector nml_flat = normalize(v@N * {1, 0, 1});
v@P -= nml_flat * sin(u_mod) * 0.12;
v@P.y *= u_fit;

Thank you!

hex_nut.hiplc

Edited by konstantin magnus

Share this post


Link to post
Share on other sites
4 hours ago, konstantin magnus said:

How can I multiply vectors so they end up on an infinite plane defined by a position and a normal?

By "multiplying" you mean projecting them onto a plane? If so, cross() seems to be enough:

// P is a vector in world space and POS, NORM are point 
// and (unit) normal vector defining infinite plane
vector p0 = P - POS;
vector projected  = cross(p0, NORM);
       projected  = cross(NORM, projected) + POS;

 

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, symek said:

By "multiplying" you mean projecting them onto a plane

Thank you! And yes, by 'multiplying vectors' I was thinking of extending or shortening them, not thinking of using cross products here. So this is a visual summary in 5 steps:

project_on_plane.thumb.png.f7a40885e237faa45ff23780bceb4aae.png

  1. When we want to project the grey points from the inner circle on the plane of the outer points and their normals (turqoise),
  2. we aim in the opposite direction facing away from the plane points by subtracting circle point positions from the plane positions (yellow),
  3. create rectangular vectors to the plane normals by calculating a cross product of the aim direction and the plane points normals (red),
  4. and build the cross product of the planes normals and the rectangular directions while adding the planes position (green).
  5. When applying this result to the circle points positions, all points are projected on their targeted planes.
int    pt_plane  = nearpoint(1, v@P);
vector pos_plane = point(1, 'P', pt_plane);
vector nml_plane = point(1, 'N', pt_plane);

v@dir = v@P - pos_plane; // yellow
v@rect = cross(v@dir, nml_plane); // red
v@proj = cross(nml_plane, v@rect) + pos_plane; // green

v@P = v@proj;

 

project_on_plane.hiplc

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

Oh man! You did art with those vectors. I'm jealous!

 

tatoue.png.5a1c90675cf9f0bc71a610014ecc3e8c.png

Edited by symek
visual proof added!
  • Like 1

Share this post


Link to post
Share on other sites

My brain is pleased :)

Share this post


Link to post
Share on other sites
On 3/10/2019 at 2:55 PM, konstantin magnus said:

One question remains: How would one scale radial vectors so a circle turns into an n-gon?

int   num_faces = chi("num_faces");

int    nface = floor((float)@ptnum * num_faces / @numpt);
float  alpha = M_PI * (1+2*nface) / num_faces;
int    pin   = nface * @numpt  / num_faces;

vector nml   = set(cos(alpha), 0, -sin(alpha));
vector pos   = point(0, "P", pin);

@P = @P - pos;
@P = cross(@P, nml);
@P = cross(nml, @P) + pos;

Those divisions by num_faces distract me, but I can't do better :blush:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×