Angle between north and face
-
I have come a cross several posts about angle between but none of them answered my question.
I want to calculate angle between north and any face in model.
There should not any restriction if i change north or model.#the way how i get north angle north_angle = Sketchup.active_model.shadow_info['NorthAngle']
Below is algorithm what I want to achieve:
[pre:2rvuqfdo]x=north_angle
y=face_angle
z=angle_between
if(x>360)
z=y
else
if(x>0)
if(x+y>360)
z=x-360+y
else
z=x+y
end
end
end[/pre:2rvuqfdo] -
Can some one see:
- why if I change north angle result is not changing?
` north_angle = Sketchup.active_model.shadow_info['NorthAngle']
north_vector = Y_AXIS.clone
north_vector.z = 0
flat_normal = entity.normal.clone
flat_normal.z = 0
point = ORIGIN
up = Z_AXIS
rotation = north_angle.degrees
tr = Geom::Transformation.rotation(point,up,rotation)
north_vector.transform (tr)
angle = (flat_normal.angle_between(north_vector)).radiansif flat_normal.x < 0 angle = 360-angle else angle end`
-
Hi!
No response ey? I give it a try.
Maybe this code is part of a larger piece, otherwise I have a little trouble following your logic.
Have never used shadow info, and do not have time to look up the methods revolving that.
Does it really return an angle?What is entity ? a face?
Unless you are going to use those variables later why not just enter:
tr = Geom::Transformation.rotation(ORIGIN, Z_AXIS, rotation)
Does not really matter for solving this problem though..Try putting a bang to it! Edit in place..
north_vector.transform! (tr)
-
@krisjaniszakis said:
Can some one see:
- why if I change north angle result is not changing?
north_vector.transform(tr)
@unknownuser said:
](http://www.sketchup.com/intl/en/developer/docs/ourdoc/vector3d#transform)":d4kps6d6]The original vector is unchanged by this method.
@unknownuser said:
](http://www.sketchup.com/intl/en/developer/docs/ourdoc/vector3d#transform!)":d4kps6d6]The vector itself is modified.
-
Hi Dan.
Yes modify the vector in place was the idea. Bad one ?
Found a roundup regarding shadow info that might be intresting for Kris:
http://sketchucation.com/forums/viewtopic.php?f=180&t=28829&p=250402&hilit=northangle#p250402
Havent delt with shadow info before so I can only hint some links..
-
@jolran said:
Hi!
No response ey? I give it a try.
Maybe this code is part of a larger piece, otherwise I have a little trouble following your logic.
Have never used shadow info, and do not have time to look up the methods revolving that.
Does it really return an angle?What is entity ? a face?
Unless you are going to use those variables later why not just enter:
tr = Geom::Transformation.rotation(ORIGIN, Z_AXIS, rotation)
Does not really matter for solving this problem though..Try putting a bang to it! Edit in place..
north_vector.transform! (tr)
I just wanted to automating angle between north and face.
With entity I meant "face".Here is updated code
` north_angle = Sketchup.active_model.shadow_info['NorthAngle']
flat_normal = entity.normal.clone
flat_normal.z = 0
north_vector = Y_AXIS.clone
north_vector.z = 0
point = ORIGIN
up = Z_AXIS
rotation = north_angle.degrees
tr = Geom::Transformation.rotation(point,up,rotation)
north_vector.transform! (tr)
angle = (north_vector.angle_between(flat_normal)).radiansif flat_normal.x < 0 angle = 360-angle else angle end`
And here is Sketchup screenshot with my experiment.
For this example script gives that angle between will be 100but not 50, where is the problem ?
-
Hi!
I think it's important to determine what you mean angle between north and face.
I wonder if it's the face normal you want to work with in this example?
Maybe that why youre not getting the result you was expecting.(if the face is vertical al the time(not flat on the ground), then the normal vector comparison should be a reliable method.)
You might perhaps be happier working with some of the face edges?
If your face is fairly uncomplex and you know that a particular edge has a min or max X,Y,Z value you can retrieve that edge and use edge.line[1], and do a comparison from there.
Just an idea..
-
I'm not sure what are you looking for but here you have the
angle between north an a vector normal to face (with z=0) (Not valid for face in xy plane)northvec=Geom;;Vector3d.new( Math;;sin(Sketchup.active_model.shadow_info['NorthAngle'].degrees), Math;;cos(Sketchup.active_model.shadow_info['NorthAngle'].degrees),0) vec=face.normal vec.z=0 result= northvec.angle_between(vec).radians
-
Thanks it was the thing I was looking for
Advertisement