We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

Circle rotation in space. Can't calculate x coordinate.

Anonymous
Not applicable
I'm trying to make a circle that has a center in origo. Se the illustration below.
I first put the circle on the horizontal layer (XY-layer and z=0). Center is origo (x=y=z=0) That works fine.
I tilt the circle with an angle to the horizontal layer. I call this angleXY.
The circle cuts through the horizontal layer in the X-axis. The circle is tilted counter-clockwise. This also works fine.
But the problem occures when I try to rotate the tilted circle counterclockwise around the z-axis. The angle is vinkeXZ. I can't figure out how to calculate the x-coordinates. I 've tryed many formulas, but the coordinates eighter give me an ellipsis or a line.

Here is the code (vinkel norwegian for angle):

fromDegrees = 10
toDegrees = 360
stepDegrees = 10
centerX = 0
centerY = 0
centerZ = 0
radiusP = 0.5
vinkelXZ = 45 ! Angle from the X-axis counterclockwise around the Z-axis (centerX and centerY=0)
vinkelXY = 45 ! Angle between the horizontal-layer and the circle.
! Counterclockwise around the X-axis (centerY=0)
angle = 0
GOSUB "GenerateCircularCoordinates"


END


"GenerateCircularCoordinates":
! This routine calculates xyz-coordinates to a circle that tilts against the horizontal-layer
! and rotates around the Z-axis
!
! Calculate the trigonometric factores to angles that do not change in the loop.
sinVinkelXY = SIN(vinkelXY)
cosVinkelXY = COS(vinkelXY)
sinVinkelXZ = SIN(vinkelXZ)
cosVinkelXZ = COS(vinkelXZ)

FOR vinkel = fromDegrees TO toDegrees STEP stepDegrees
deltaX = radiusP * COS (vinkel)
deltaY = radiusP * SIN (vinkel)
deltaZ = radiusP * SIN (vinkel)

x = centerX - deltaX
y = centerY - deltaY
z = centerZ
! ---------------------------------------------------
! Tilt against the horizontal-layer (XY-layer)
! Rotation around the X-axis
!
z = -y * sinVinkelXY + centerZ
y = y * cosVinkelXY + centerY
! ---------------------------------------------------
! Rotation around the Z-axis
!
y = y + x*sinVinkelXZ
x = x*cosVinkelXZ
!
! PUT x, y, z, angle
IF vinkel <> 0 THEN
ADD x, y, z
TEXT 0.005, 0, vinkel
DEL 1
LIN_ x - 0.01, y - 0.01, z - 0.01, x + 0.01, y + 0.01, z + 0.01
ENDIF

NEXT vinkel
RETURN

CircleIll.jpg
12 REPLIES 12
Anonymous
Not applicable
Anne wrote:
I tested out my husbands brain yesterday... (...) A friend of me told me today that her husband was really good in mathematics, so I have to test him 😉
Poor Norwegian husbands...
Ralph Wessel
Mentor
Anne wrote:
But the problem occures when I try to rotate the tilted circle counterclockwise around the z-axis. The angle is vinkeXZ. I can't figure out how to calculate the x-coordinates. I 've tryed many formulas, but the coordinates eighter give me an ellipsis or a line.
Try the script below. I've typed this from memory, so it might have errors. Hopefully the comments make the meaning clear.
!-----------------------------------------------------------
!Set up rotation angles
! xRotationAngle is rotation angle about X axis
! zRotationAngle is rotation angle about Z axis
!-----------------------------------------------------------
cosX = cos(-xRotationAngle)
sinX = sin(-xRotationAngle)
cosZ = cos(-zRotationAngle)
sinZ = sin(-zRotationAngle)

!Rotate a point about 'X' axis
xIn = 20
yIn = 5
zIn = 0
gosub "doXRotate"

!Rotate about 'Z' axis
gosub "doZRotate"

!The rotated point is contained in (xIn, yIn, zIn)

end

!-----------------------------------------------------------
! Rotate a point about the x axis

! In/Out:
! yIn: The Y coordinate of the point to rotate
! zIn: The Z coordinate of the point to rotate
!-----------------------------------------------------------
"doXRotate":
yOut = zIn * sinX + yIn * cosX
zIn = zIn * cosX - yIn * sinX
yIn = yOut
return


!-----------------------------------------------------------
! Rotate a point about the z axis

! In/Out:
! xIn: The X coordinate of the point to rotate
! yIn: The Y coordinate of the point to rotate
!-----------------------------------------------------------
"doZRotate":
xOut = xIn * cosZ + yIn * sinZ
yIn = -xIn * sinZ + yIn * cosZ
xIn = xOut
return
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
This worked fine! You deserve a big hug