PolarPattern with Z-axis shift depending on the function of angle

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
JackkDBA
Posts: 60
Joined: Tue Jan 04, 2022 7:43 am
Location: Poland
Contact:

Re: PolarPattern with Z-axis shift depending on the angle

Post by JackkDBA »

papyblaise wrote: Wed Nov 30, 2022 8:00 am you need a powerful counter to calculate Z = Z Total /Number of Holes :!:
I don't get it.

IMHO I need to reference current angle (used by PolarArray for each of objects created) to use it in "Polar array" --> "Interval Axis" --> "z" field. Unfortunately, I don't know how to do this.
Best regards,
Jacek
User avatar
papyblaise
Veteran
Posts: 7869
Joined: Thu Jun 13, 2019 4:28 pm
Location: France

Re: PolarPattern with Z-axis shift depending on the angle

Post by papyblaise »

I don't understand your idea either.
you have 20 holes, the offset in Z is a function of the total offset of the 20th hole, so the offset of 1 hole is Total / 20
there is no need for sine or other trig
User avatar
JackkDBA
Posts: 60
Joined: Tue Jan 04, 2022 7:43 am
Location: Poland
Contact:

Re: PolarPattern with Z-axis shift depending on the angle

Post by JackkDBA »

I need the holes to be positioned in Z-axis according to sinus function of the angle, not linearly going down or up.
Best regards,
Jacek
chrisb
Veteran
Posts: 53920
Joined: Tue Mar 17, 2015 9:14 am

Re: PolarPattern with Z-axis shift depending on the angle

Post by chrisb »

JackkDBA wrote: Tue Nov 29, 2022 7:26 am I'd like to make 20 holes in a cylinder. The main problem is that the holes must be shifted in Z-axis using sinus function like this:
- hole number 1: shift = sin(0 * 360/20) * shift_amplitude = sin(0deg) * shift_amplitude
- hole number 2: shift = sin(1 * 360/20) * shift_amplitude = sin(18deg) * shift_amplitude
If I understand it right, then all these points lie on a tilted circle. I played a bit with this (and also with other curves, created by addon 3DParametricCurve) and PointArray and PathArray. I can well place the cylinders for the holes, but I couldn't get the oriention right.
So I am now convinced, that you need some Python for it.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
JackkDBA
Posts: 60
Joined: Tue Jan 04, 2022 7:43 am
Location: Poland
Contact:

Re: PolarPattern with Z-axis shift depending on the function on angle

Post by JackkDBA »

How may I reference current angle used by PolarArray (or PolarPattern) in each iteration?
It would be enough if I have iteration number (N from my first post in this topic).
Best regards,
Jacek
User avatar
papyblaise
Veteran
Posts: 7869
Joined: Thu Jun 13, 2019 4:28 pm
Location: France

Re: PolarPattern with Z-axis shift depending on the function of angle

Post by papyblaise »

I'm in a big hole of loneliness
are the holes evenly spaced 18° apart
is the Z rise continuous (eg 2mm at each hole)
what is the use of the requirement to have Z f*sin18*N , if the progression is constant , a constant Z is enough
can you attach an example or something more explicit
chrisb
Veteran
Posts: 53920
Joined: Tue Mar 17, 2015 9:14 am

Re: PolarPattern with Z-axis shift depending on the function of angle

Post by chrisb »

papyblaise wrote: Wed Nov 30, 2022 11:33 am I'm in a big hole of loneliness
are the holes evenly spaced 18° apart
is the Z rise continuous (eg 2mm at each hole)
what is the use of the requirement to have Z f*sin18*N , if the progression is constant , a constant Z is enough
Z rise is not constant. Think of a diagonal cut through a tube: You get an elliptical cut with non constant distances.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
JackkDBA
Posts: 60
Joined: Tue Jan 04, 2022 7:43 am
Location: Poland
Contact:

Re: PolarPattern with Z-axis shift depending on the function of angle

Post by JackkDBA »

papyblaise wrote: Wed Nov 30, 2022 11:33 am are the holes evenly spaced 18° apart => YES
is the Z rise continuous (eg 2mm at each hole) => NO
what is the use of the requirement to have Z f*sin18*N => I have such requirement, that's all
if the progression is constant , a constant Z is enough => progression in Z-axis is not constant but it depends on the sinus of the angle for current instance of the object created
Suppose we have a 1-cycle (0...2*pi) sinus function printed on a paper. When we wrap the paper around the cylinder, there is a continuous line on it.
I want the center of the holes to be in places where the line is visible on the cylinder.
Last edited by JackkDBA on Wed Nov 30, 2022 12:20 pm, edited 1 time in total.
Best regards,
Jacek
User avatar
papyblaise
Veteran
Posts: 7869
Joined: Thu Jun 13, 2019 4:28 pm
Location: France

Re: PolarPattern with Z-axis shift depending on the function of angle

Post by papyblaise »

ha yes am I stupid, it gives a sinusoid rolled up on a roll
Sorry, I haven't done math for 50 years. :oops:
did I understand everything correctly with my line of green peas :?:
with that of small blue cylinders, I have a problem: I can't orient them towards the center :!:
Attachments
hole sinus.JPG
hole sinus.JPG (31.82 KiB) Viewed 624 times
hole sinus.FCStd
(207.3 KiB) Downloaded 14 times
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: PolarPattern with Z-axis shift depending on the function of angle

Post by Roy_043 »

A solution using a minimal amount of Python code:

Open the attached file test-arr.FCStd and run:

Code: Select all

import FreeCAD as App
import math

doc = App.ActiveDocument
lnk = doc.Link
arr = doc.Array

shift = 10
for elm, place in zip(lnk.ElementList, arr.PlacementList):
    axis = place.multVec(App.Vector (0, 0, 1))
    ang = axis.getAngle(App.Vector (1, 0, 0))
    place.translate(App.Vector(0, 0, math.sin(ang) * shift))
    elm.Placement = place

doc.recompute()
Edit: there was a mistake in the code.
Edit 2: using multVec now... 8-)
Attachments
test-arr.FCStd
(11.07 KiB) Downloaded 14 times
Post Reply