What is XDirection property?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
- wandererfan
- Veteran
- Posts: 6309
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
What is XDirection property?
continued from https://www.forum.freecadweb.org/viewto ... 15#p356207
The XDirection property defines the XAxis of the projection in terms of the 3d coordinate system. It's main use is to ensure that Views (such as Sections) that are based on other Views have the correct orientation relative to the original.
The XDirection property defines the XAxis of the projection in terms of the 3d coordinate system. It's main use is to ensure that Views (such as Sections) that are based on other Views have the correct orientation relative to the original.
Re: What is XDirection property?
hi
example 1,0,1
create a Draft.makeLine((0,0,0), (1,0,1)) : direction = Xd = (1,0,1)
mario
example 1,0,1
create a Draft.makeLine((0,0,0), (1,0,1)) : direction = Xd = (1,0,1)
Code: Select all
import math
try: # Direction
edgeO = Gui.Selection.getSelection()[0] # edge
edgeObject = edgeO.Shape.Edges[0]
e = edgeObject
direction = e.Vertexes[1].Point.sub(e.Vertexes[0].Point)
FreeCAD.Console.PrintMessage("\n" + "Direction Objet = " + str(direction) + "\n")
##for angle X,Z (1,0,1)
deltaX = e.Vertexes[1].Point.x - e.Vertexes[0].Point.x
deltaZ = e.Vertexes[1].Point.z - e.Vertexes[0].Point.z
angle = math.atan(deltaZ / deltaX) # radian
FreeCAD.Console.PrintMessage("\n" + "Angle XZ (1,0,1)(Radian) = " + str(angle) + "\n")
FreeCAD.Console.PrintMessage("\n" + "Angle XZ (1,0,1)(Degrees) = " + str(math.degrees(angle)) + "\n")
except Exception:
None
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
- Tamirov.ru
- Posts: 89
- Joined: Thu Feb 07, 2019 3:21 pm
- Contact:
Re: What is XDirection property?
Thank you!
Generally speaking, I have understood.
Generally speaking, I have understood.
Частный вебмастер, разработка сайтов, продвижение сайтов.
- wandererfan
- Veteran
- Posts: 6309
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: What is XDirection property?
I must think about it at least twice.
- JoshuaCall
- Posts: 50
- Joined: Tue Dec 17, 2019 3:43 am
Re: What is XDirection property?
Why is the view under "Projection CS rotated 45* from 3d CS" rotated clockwise instead of counterclockwise? If the projection plane's x axis is rotated to be in line with the vector (1,0,1), it would rotate counterclockwise.
- wandererfan
- Veteran
- Posts: 6309
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: What is XDirection property?
Instead of "x axis is rotated", think of it as "use (1,0,1) in R3 as the XDirection when displaying the projection". So in effect you are rotating (1, 0, 1) to (1, 0, 0) which is a clockwise movement.JoshuaCall wrote: ↑Mon Jan 20, 2020 5:22 am Why is the view under "Projection CS rotated 45* from 3d CS" rotated clockwise instead of counterclockwise? If the projection plane's x axis is rotated to be in line with the vector (1,0,1), it would rotate counterclockwise.
- Attachments
-
- XDirection101.png (46.76 KiB) Viewed 2819 times
- JoshuaCall
- Posts: 50
- Joined: Tue Dec 17, 2019 3:43 am
Re: What is XDirection property?
Wandererfan,
I propose making the following changes to the wiki documentation, and possibly the tool tip, for the Direction and XDirection properties of TechDraw NewView.
Direction:
Code: Select all
The direction vector to the position you are looking from.
XDirection:
Tool tip:
Code: Select all
R3 vector moving onto projection plane x axis. Rotates view
Code: Select all
This vector controls the rotation of the view around the Direction.
One way to think of the rotation this property can produce is as follows: the projection plane undergoes the same linear transformation as the linear transformation which moves the XDirection vector in R3 onto the projection plane's original x axis.
The transformation may fail, in which case an error will be produced: failed to create projection CS.
- wandererfan
- Veteran
- Posts: 6309
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: What is XDirection property?
It took me a long (embarassingly long ) time to figure out that Direction is the normal of the projection plane. So it points from the image to the viewer. So any improvement in the documentation of this property is welcome.JoshuaCall wrote: ↑Mon Jan 20, 2020 7:52 pm I propose making the following changes to the wiki documentation, and possibly the tool tip, for the Direction and XDirection
Direction:Code: Select all
The direction vector to the position you are looking from.
I don't understand the first part. XDirection can rotate and/or mirror the view
The second paragraph is a tough read. Don't have a replacement off the top of my head.wiki documentation:Code: Select all
This vector controls the rotation of the view around the Direction. One way to think of the rotation this property can produce is as follows: the projection plane undergoes the same linear transformation as the linear transformation which moves the XDirection vector in R3 onto the projection plane's original x axis. The transformation may fail, in which case an error will be produced: failed to create projection CS.
Usually the failure is because Direction & XDirection are parallel/antiparallel.
Thanks for doing this.
- JoshuaCall
- Posts: 50
- Joined: Tue Dec 17, 2019 3:43 am
Re: What is XDirection property?
What I'm trying to say is that the view will be rotated by some angle. What angle? The angle that you rotate the "XDirection" property vector by to move it in 3D space to where the projection plane's x-axis is sitting.wandererfan wrote: ↑Tue Jan 21, 2020 1:42 am The second paragraph is a tough read. Don't have a replacement off the top of my head.
Let me put that in terms of the 45 degree rotation example that you gave.
What I'm trying to say is that the view will be rotated by some angle. What angle? The angle that you rotate (1,0,1) by to move it in 3D space to position (1,0,0). That is, 45 degrees clockwise.
Let me give another example.
Take a look at the "Generating 2D drawings" manual page example file.
https://github.com/JoshuaCall/FreeCAD-m ... wing.FCStd
Look at the view named "View."
"View" will be rotated by some angle so that it is no longer the standard top view. What angle? The angle that you rotate (0,-1,0) by to move it in 3D space to position (1,0,0). That is, 90 degrees counterclockwise. Vector (1,0,0) was the original x-axis of the projection plane for the standard top view (the standard top view has direction vector (0,0,1)).
I'm trying to reword it like this because thinking about it this way was the only way that allowed me to predict the effect of the XDirection property. Let me know if this wording makes more sense, or if I still need to rework it.
- wandererfan
- Veteran
- Posts: 6309
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: What is XDirection property?
If you're just trying to rotate the view for improved esthetics, you should use "Rotation". It is much easier to understand the effect, and it doesn't affect the CS.JoshuaCall wrote: ↑Tue Jan 21, 2020 3:47 am What I'm trying to say is that the view will be rotated by some angle. What angle? The angle that you rotate the "XDirection" property vector by to move it in 3D space to where the projection plane's x-axis is sitting.
XDirection was only exposed to allow correction of messed up CS when opening older files. The code tries to guess what the XDirection should be when it reads a file without the XDirection property ( <19 and some early 19). Sometimes it gets it right, sometimes not.
Predicting XDirection's effect is easy for some changes: (1,0,0) to (-1,0,0) is a mirror through Y axis, (1,0,0) to (0,1,0) is a 90* rotation. It gets more difficult to predict with non-ortho Directions.
Generally, the rule for a good XDirection is: Lift your left arm to the front and point back along the Direction vector. Raise your right arm straight out to the side. Your right index finger will point in the required XDirection.
If your View looks wrong (ie mirrored or rotated) and it fails the finger point test, only then should you start changing XDirection.