几何尺寸与公差论坛

 找回密码
 注册
查看: 837|回复: 0

【转帖】determine whether sketch is facing towardaway from origin,

[复制链接]
发表于 2009-4-13 10:19:27 | 显示全部楼层 |阅读模式
determine whether sketch is facing toward/away from origin,
i am working i a macro and need to be able to determine within the macro whether or not a sketch is facing toward or away from the origin. i would then use this information in an if statement later.
in my macro a sketch is created (gear tooth profile) and then within the same macro another sketch is created to define the path of a swept cut. the path would change depending on whether the first sketch was facing toward the origin or away.
can anyone help me out?

check out our whitepaper library.
i'm not sure myself, but could you create points and have it determine the coordinates of the points for the path?
a guess...
chris
solidworks/pdmworks 08 3.1
autocad 08
what do you mean by "facing the origin"?  do you mean that the sketch is on some plane that does not pass through the origin, and you need to determine whether the sketch's normal vector points toward or away from the origin?
-handleman, cswp (the new, easy test)
correct, the sketch is on some plane that does not pass through the origin, and i need to determine whether the sketch's normal vector points toward or away from the origin.
really, when i create my swept cut path i just want to ensure that it is going through the part.
referencing the attached screen shot, if i started my gear tooth sketch on the opposite of the part, my swept path would have still gone to the left rather than intersecting the part.  
the only way i can think of to do this is fairly complicated.  the basic idea is to get the normal vector for the plane or face on which the sketch resides and compare it to the closest distance between the plane/face and the origin.
to get the plane or face on which the sketch resides, use sketch::getreferenceentity.  this will be either a plane or a planar face.  the method for dealing with each is slightly different.  do you have any experience with vector algebra and transformation matrices?  i sure hope so...
if the sketch resides on a plane, you will need to use refplane::transform to get the mathtransform object for the plane.  this mathtransform is a 3d transformation matrix that basically gives the data for the plane.  from this you can create the normal vector mathvector object).
if the sketch resides on a planar face, then the normal vector (mathvector) can be had directly from face2::normal.
now that you have a normal vector to the face or plane (vector length is unimportant) you need to get a vector from your plane/face to the origin.  this can be created from the point data gotten from modeldoc2::closestdistance.  if you have a plane, the vector gotten through closestdistance will be either pointing in exactly the same direction as the normal vector or in exactly the opposite.  if you have a planar face, the vector may or may not be directly normal to the face, because the origin may be outside the boundary of the normal projection of the planar face.  however, this doesn't matter.  all you care about is the angle between the two vectors.  if the angle is greater than 90 degrees, your plane normal points away from the origin.  if it's less than 90 degrees, the normal points toward the origin.  take the dot product of the two vectors using mathvector::dot.  if the dot product is a negative number then the angle is greater than 90 degrees and the sketch normal points away from the origin.  if the dot product is positive then the angle is less than 90 degrees and the normal points toward the origin.
-handleman, cswp (the new, easy test)
if possible and not too much trouble, could you provide sample code that one may use to do something like this? i am not as familiar with solidworks macros as i would like to be.
regardless, thanks for your assist. you've been a great resource.
unfortunately, i don't have anything.  i'm also pretty short on time as i'm trying to get ready to be out on vacation.  the distance mate macro found at
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-24 02:38 , Processed in 0.035904 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表