Can not get Transform (move and rotate ) to work as I planned.

jonathan.taVCBM2
Enthusiast
Enthusiast

Can not get Transform (move and rotate ) to work as I planned.

jonathan.taVCBM2
Enthusiast
Enthusiast

Hi ,

I am trying to find points that are along a wall, or room separation line and then "move" into and out of the room.  

I get the midpoint , angle of the wall and and then create two transforms, one for translation and one rotation around the midpoint, I first translate then rotate .

I don't get what I expected  - it seems that rotation have no effect . Any ideas would be greatly appreciated .  

See drawing and code below (the CreateModelLine does what it says on the box 🙂

Thanks , jonathan 

XYZ p1 = new XYZ(0.0, 0.0, 0.0);
XYZ p2 = new XYZ(6.0, 6.0, 0.0);
XYZ midpoint = (p1 + p2) / 2;
double an90 = p1.AngleTo(p2);
ModelLine a = CreateModelLine(doc, p1, p2);
Transform tr1 = Transform.CreateTranslation(new XYZ(0.0, 1.0 ,0.0));
Transform tr2 = Transform.CreateRotationAtPoint(XYZ.BasisZ, an90, midpoint);
XYZ p3 = tr1.OfPoint(midpoint);
XYZ p4 = tr2.OfPoint(p3);
ModelLine b = CreateModelLine(doc, midpoint, p3);
ModelLine c = CreateModelLine(doc, midpoint, p4);

 

jonathantaVCBM2_0-1669299161419.png

 

Jonathan Talisman
BIM Developer
0 Likes
Reply
Accepted solutions (1)
315 Views
4 Replies
Replies (4)

ricaun
Advisor
Advisor

I tested your code.

 

Yes, the rotation has no effect because the an90 is zero.

 

Usually, the AngleTo method is used to get the angle between two Vectors, or you can use Math.PI to set a specific angle like 90deg = Math.PI / 2.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes

jonathan.taVCBM2
Enthusiast
Enthusiast

@ricaun thanks for your help .

It is true that the angle is 0, which I don't get at all. 😯 

The angle between the points (0,0,0) and (6,6,0) is 45 degrees , isn't it ? As far as I understand it - id does not matter if it's called a point or a vector, it's an XYZ object with methods. (The way I understand it -  point is a vector from the origin ).

I have tried the angle from 

I have also tried AngleOnPlaneTo with XYZ(0,0,1) as the plane and also got 0 as the angle . 

How else would you get the angle between two points ? 

Jonathan 

 

 

Jonathan Talisman
BIM Developer
0 Likes

ricaun
Advisor
Advisor
Accepted solution

In Revit a vector and point is the same class XYZ.

 

But the problem is that you are trying to get the angle between a vector (0,0,0) and a vector (0.5,0.5,0). A zero vector is not pointing in any direction, that's the reason you are getting the angle zero between the 2 vectors.

 

Just imagine a person and each arm is a vector, it's easy to find the angle between the two arms in any position, but if you remove um arm what happen with the angle goes to zero.

 

So the angle gonna be 45deg in the vector BasisX and BasisY, like the code:

XYZ p2 = new XYZ(6.0, 6.0, 0.0);
Console.WriteLine($"XYZ.BasisX: {XYZ.BasisX.AngleTo(p2) * 180 / Math.PI}"); // 90deg
Console.WriteLine($"XYZ.BasisY: {XYZ.BasisY.AngleTo(p2) * 180 / Math.PI}"); // 45deg
Console.WriteLine($"XYZ.BasisZ: {XYZ.BasisZ.AngleTo(p2) * 180 / Math.PI}"); // 45deg

 

A angle between two points does not make sense, but you can get a direction(vector) from a point to another one.

XYZ direction = (p2 - p1).Normalize();

 

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes

jonathan.taVCBM2
Enthusiast
Enthusiast

Hi @ricaun ,

I was just looking at a vector between the two points and the angle between that vector and Yaxis.

Thanks , Jonathan

Jonathan Talisman
BIM Developer
0 Likes