## What is XDirection property?

Discussions about the development of the TechDraw workbench
wandererfan
Posts: 3848
Joined: Tue Nov 06, 2012 5:42 pm

### What is XDirection property?

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.

XDirectionExpl.png (68.27 KiB) Viewed 652 times
mario52
Posts: 2921
Joined: Wed May 16, 2012 2:13 pm

### 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)

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)(Degrees) = " + str(math.degrees(angle)) + "\n")

except Exception:
None

``````
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
Tamirov.ru
Posts: 85
Joined: Thu Feb 07, 2019 3:21 pm
Contact:

### Re: What is XDirection property?

Thank you!
Generally speaking, I have understood.
Частный вебмастер, разработка сайтов, продвижение сайтов.
wandererfan
Posts: 3848
Joined: Tue Nov 06, 2012 5:42 pm

### Re: What is XDirection property?

Tamirov.ru wrote:
Sat Dec 28, 2019 12:33 pm
Generally speaking, I have understood.
I must think about it at least twice.
JoshuaCall
Posts: 44
Joined: Tue Dec 17, 2019 3:43 am

### Re: What is XDirection property?

wandererfan wrote:
Sat Dec 28, 2019 2:24 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.
wandererfan
Posts: 3848
Joined: Tue Nov 06, 2012 5:42 pm

### Re: What is XDirection property?

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.
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.
Attachments
XDirection101.png (46.76 KiB) Viewed 421 times
JoshuaCall
Posts: 44
Joined: Tue Dec 17, 2019 3:43 am

### Re: What is XDirection property?

wandererfan wrote:
Mon Jan 20, 2020 1:57 pm
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.``
The reason for this change is that I confused the wording "the direction you are looking from" with the concept of "the direction vector you are looking along." Due to this misunderstanding, I thought that the view should have been a top view when it was actually a bottom view and vice versa. Alternatively, we could change the name of the property from "direction" to "viewing position" or something similar.

XDirection:
Tool tip:

Code: Select all

``R3 vector moving onto projection plane x axis. Rotates view``
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.``````
Let me know what you think of these changes, if you need clarification, or if you have improvements, and I'll try to implement anything that we agree on.
wandererfan
Posts: 3848
Joined: Tue Nov 06, 2012 5:42 pm

### Re: What is XDirection property?

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.``
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.
XDirection:
Tool tip:

Code: Select all

``R3 vector moving onto projection plane x axis. Rotates view``
I don't understand the first part. XDirection can rotate and/or mirror the view
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.``````
The second paragraph is a tough read. Don't have a replacement off the top of my head.

Usually the failure is because Direction & XDirection are parallel/antiparallel.

Thanks for doing this.
JoshuaCall
Posts: 44
Joined: Tue Dec 17, 2019 3:43 am

### Re: What is XDirection property?

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.
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.

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.

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
Posts: 3848
Joined: Tue Nov 06, 2012 5:42 pm

### Re: What is XDirection property?

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.
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.

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.