Page 1 of 2 12 LastLast
Results 1 to 40 of 72

Thread: normal at corner of rectangular

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    normal at corner of rectangular

    Hey guys

    it would be much appreciated if anyone could give a hint ...I need to find the normal at the corner of rectangular? what I have done is? I calculate the cross product of both intersected segments which give the normal, but I am not convinced with my answer as the cross product give me just a number, and I need a vector i.e x-y coordinates

  2. #2
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    Re: normal at corner of rectangular

    if your answer is just a number, then as you have said, it cannot be correct. Why don't you post more of the problem? This isn't homework is it?

    Anyway, since it's a rectangle it should be relatively easy to see if you have the right answer. The magnitude of the cross product should equal the area of the rectangle. you just have to make sure the vector is in the right direction.
    Last edited by wy125; Nov 3rd, 2008 at 02:21 PM.

  3. #3
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: normal at corner of rectangular

    First of all, your question doesn't make sense. The normal at the corner of a rectangular..? I guess you mean a rectangle?
    Then you say you use the cross product to calculate the normal, which tells me that you are working in 3 dimensions (eg: you need the vector normal to the plane (a), rather than the vector normal to one side of the rectangle (b)).


    However, you then say you expect a vector with 2 coordinates! This cannot be right: if you use the cross product you are by definition working in 3D and the result is a vector of 3 dimensions. (Of course, one or more can be zero but it's still there!)

    Finally, if you are working in 2 dimensions than the vector normal to the corner of a rectangle is undefined: the corner is a single point and every vector (except the zero vector) is normal to a point.

    If you are working in 3D then the normal vector to a rectangular plane is always the same in direction and magnitude no matter where you want to calculate it (wether it is on a corner or in the middle of the rectangular plane). To calculate this vector you need either the equation of the plane (ax + by + cz = d) or you need the two vectors that span the plane (and take their cross product).


    So if you want more help, clarify your question.
    Are you working in 2D or 3D?
    What exactly do you mean by 'intersected segments'?
    The result of a cross product is a vector, not a number so you definitely calculated it wrongly (perhaps you used the dot product by mistake?)

  4. #4
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    Re: normal at corner of rectangular

    nick you're right of course, but i think he means that taking the sides that intersect at a corner as vectors and computing their cross product. Of course, it's best if he clarifies...

  5. #5
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: normal at corner of rectangular

    Yes that would make the most sense (why didn't I think of that lol...).

    So what you are trying to do is, you take two sides of the rectangle that join somewhere on the corner of the rectangle (you don't take parallel sides), you are trying to compute the normal vector to that rectangle (plane) by taking their cross product?

    Can you tell us how you are trying to calculate the cross product? Just take two arbitrary vectors (a,b,c) and (x,y,z) for example, can you then tell us what their cross product is?

  6. #6
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: normal at corner of rectangular

    You probably accidentally used a formula for the magnitude of the cross product. The (cartesian) formula for doing (a1, a2, a3) cross (b1, b2, b2) is (a2b3 − a3b2, a3b1 − a1b3, a1b2 − a2b1).

    Once you use that, you can easily check your answer by taking the dot product of your normal vector with each of the lines it's supposed to be perpendicular to. If the dot product is zero in each case, you're good.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    Quote Originally Posted by NickThissen
    Yes that would make the most sense (why didn't I think of that lol...).

    So what you are trying to do is, you take two sides of the rectangle that join somewhere on the corner of the rectangle (you don't take parallel sides), you are trying to compute the normal vector to that rectangle (plane) by taking their cross product?

    Can you tell us how you are trying to calculate the cross product? Just take two arbitrary vectors (a,b,c) and (x,y,z) for example, can you then tell us what their cross product is?
    Thanks guys for ur time I want to calculate the normal vector at each point on a polygon(5 vertices) in 2-dim included the corners........ what I have done to calculate the normal for a point on the segment is finding the normal equation which can be constructed from the slope and one point then construct the normal from the line equation which is just (coefficient of x, coefficient of y) Is that the correct way and for the normal at corners I had calculated the cross product of two sides of the rectangle that join somewhere on the corner of the rectangle. I have used( The two-dimensional equivalent of a cross product is a scalar:

    LaTeX Code: \\hat{x} \\times \\hat{y} = x_{1}y_{2}-x_{2}y_{1}

    It's also the determinant of the 2x2 row matrix formed by the vectors.

    what about if I consider the corner as a point on the segment anf find its normal as other point but mmmmm then we will use the uniqueness.....Buy the way I need to find the inward normal, this is not homework but iam building some code which need these geometric inf.

  8. #8
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: normal at corner of rectangular

    So you are NOT in 3D but in 2D?
    In my picture: you are in situation (b) ?

    I don't understand exactly how you calculated the normal vector to the straight line segments, can you elaborate?

    I also have never heard of the two-dimensional equivalent of the cross product, but the only thing I can understand what it would mean is that simply the 'z-component' is zero:
    (a,b,0) x (x,y,0) = (0, 0, ay-bx) which is NOT a scalar but instead a vector that points only in the z-direction!

    If I am mistaken and the 'two dimensional equivalent of the cross product' is something else then please someone correct me. However, that would not make sense in the slightest and it would certainly not give you a normal vector.

    Also, as I have said, the vector you get by using the cross product on 2 vectors that lie in the same plane (the x-y-plane for example) then you get a vector that is perpendicular to both vectors, and thus perpendicular to that plane: you are no longer working in 2D!

    Finally, as I have said before, if you want a normal vector in the x-y-plane at the corner of your polygon: I don't think there is such a thing! The corner of the polygon is a point and you cannot say that one vector is more perpendicular to that point than any other vector! Conclusion: every vector (except the zero vector) is normal to that point.

  9. #9

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    Quote Originally Posted by NickThissen
    So you are NOT in 3D but in 2D?
    In my picture: you are in situation (b) ?

    I don't understand exactly how you calculated the normal vector to the straight line segments, can you elaborate?
    I had found the eq. of each segment of the polygon, which is (y-y_0)=m(x-x_0), where m is the slope can be found from 2 joined corners, then the eq. of the normal is (y-y_0)=m_n(x-x_0), m_n=-1/m_n ohhhhhhhhh here i need to find the x-y coordinates at each point on the polygon.......Is that correct........if no please can you guide me to the right bath

    Quote Originally Posted by NickThissen
    I also have never heard of the two-dimensional equivalent of the cross product, but the only thing I can understand what it would mean is that simply the 'z-component' is zero:
    (a,b,0) x (x,y,0) = (0, 0, ay-bx) which is NOT a scalar but instead a vector that points only in the z-direction!

    If I am mistaken and the 'two dimensional equivalent of the cross product' is something else then please someone correct me. However, that would not make sense in the slightest and it would certainly not give you a normal vector.

    Also, as I have said, the vector you get by using the cross product on 2 vectors that lie in the same plane (the x-y-plane for example) then you get a vector that is perpendicular to both vectors, and thus perpendicular to that plane: you are no longer working in 2D!
    yes you right
    Quote Originally Posted by NickThissen
    Finally, as I have said before, if you want a normal vector in the x-y-plane at the corner of your polygon: I don't think there is such a thing! The corner of the polygon is a point and you cannot say that one vector is more perpendicular to that point than any other vector! Conclusion: every vector (except the zero vector) is normal to that point.
    anyhelp????????/

  10. #10
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    Re: normal at corner of rectangular

    Sally, do you know the points of the vertices (corners) of your polygon? Are you trying to do this for the shading and lighting for 3d graphics? If you know the points of the vertices then calculating the normals is a piece of cake. The only thing you need to consider is which way is "up" on your polygon. I assume you want each of the normals pointing in the same direction.

    That said, I'm still confused about what exactly you are after. Perhaps it would help if you could tell us why you are trying to get the information?

    I took a look at what you wrote about finding equations for the line segments that make up a polygon. You don't need normals to the line segments to use in your calculation, just the points in space for each vertex of your polygon.

    As far as I know the cross product is only defined for 3D or 7D. 2D is just 3D with one of the other components zero.

  11. #11

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    Quote Originally Posted by wy125
    Sally, do you know the points of the vertices (corners) of your polygon? Are you trying to do this for the shading and lighting for 3d graphics? If you know the points of the vertices then calculating the normals is a piece of cake.
    good tell me please
    Quote Originally Posted by wy125
    The only thing you need to consider is which way is "up" on your polygon. I assume you want each of the normals pointing in the same direction.
    I want all of them pointing to the centroid of the polygon, how can I distinguish betwwen the in(up)ward direction of the normal
    Quote Originally Posted by wy125
    That said, I'm still confused about what exactly you are after. Perhaps it would help if you could tell us why you are trying to get the information?

    I took a look at what you wrote about finding equations for the line segments that make up a polygon. You don't need normals to the line segments to use in your calculation, just the points in space for each vertex of your polygon.

    As far as I know the cross product is only defined for 3D or 7D. 2D is just 3D with one of the other components zero.
    yes I forget the cross product since it works just in more than 2-dim

  12. #12
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: normal at corner of rectangular

    Have a look here, particularly equations 10, 11 and 12:
    http://mathworld.wolfram.com/Line.html

    Do you understand that?


    In the meantime, as we have asked numerous times, can you explain why you are doing this and what you are trying to achieve, because it may help us understand what you want and there may also be much easier ways of doing what you want.

  13. #13
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: normal at corner of rectangular

    I'm pretty sure Sally wants to find the normal to each edge segment, pointing inward.

    In that case the formula posted above (the one with m_n->-1/m_n) should be fine assuming the zero slope cases are accounted for properly, and assuming the edge lines point in a clockwise direction around the polygon (if it's counterclockwise, you'll get the outward normal instead of the inward one). Note that you're getting the the explicit equation for the line going through your (x0, y0) normal to the edge using your calculation and not an explicit normal vector. Calculating the vector is easy and can be done from the slope alone very easily if you draw it out.

    The normal at the edge points is really undefined. Cross products as mentioned won't help you. You might use the average normal vector, averaging the normals you get by considering each side alone. At least that should point inward, and it's probably the best definition you'll be able to find.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  14. #14

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    Quote Originally Posted by NickThissen
    Have a look here, particularly equations 10, 11 and 12:
    http://mathworld.wolfram.com/Line.html

    Do you understand that?
    Hey Nich, appreciate your time, mmmmm do I need to use t in equations 11 and 12 in the link above? as it will complicate my code....I s there any other formula??

    Quote Originally Posted by NickThissen
    In the meantime, as we have asked numerous times, can you explain why you are doing this and what you are trying to achieve, because it may help us understand what you want and there may also be much easier ways of doing what you want.
    Just I need to simplify my question, I am implementing a numerical method which walk a long the perimeter of a polygon so I need some geometric inf. such as the normal at give s

  15. #15
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: normal at corner of rectangular

    No, you don't need the t, it is simply a scalar: you have a vector (-b, a) which points in the direction of the line, and you multiply that vector by an arbitrary t, (t ranging from - infinity to + infinity) to get the entire (infinitely long) line.

    I actually meant the fact that the vector (a, b) is perpendicular (normal) to the vector (-b, a).

  16. #16

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    Quote Originally Posted by NickThissen
    No, you don't need the t, it is simply a scalar: you have a vector (-b, a) which points in the direction of the line, and you multiply that vector by an arbitrary t, (t ranging from - infinity to + infinity) to get the entire (infinitely long) line.

    I actually meant the fact that the vector (a, b) is perpendicular (normal) to the vector (-b, a).
    Really appreciate your great help and your time , just I want to conclude what I understand of finding the normal at the segment edges of the polygon.......first find the vectors along the polygon e.g the vector join the vertices v_1=(x1,y1) and v_2=(x2,y2) is v=(x2-x1,y2-y1), then the normal vector is v=(y2-y1, -(x2-x1)), so the normal vector is unique at each point on the segment, How does that sound?? and the normal vector at the corner is undefind cos we working in 2-dim. Please correct me if I have said sth doesnt make sense

  17. #17
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: normal at corner of rectangular

    I don't have much time so I may be mistaken, but it looks ok.
    The normal vector is not different at each point on the segment? It only depends on x1, x2, y1 and y2 which are fixed points (your vertices). It does depend on which segment you are on obviously, that is correct.

    The normal vector at the corner is undefined because the corner is a point in space. A point, by definition, has no normal vector as I have said before because you cannot say that one vector would be more normal to it than any other vector. In other words, every vector would be normal to a point, but it would not make sense to let any vector be a normal vector. Hence, the normal vector at a point is undefined (as far as I know, in all dimensions, not just in 2).

  18. #18

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    Quote Originally Posted by jemidiah
    I'm pretty sure Sally wants to find the normal to each edge segment, pointing inward.

    In that case the formula posted above (the one with m_n->-1/m_n) should be fine assuming the zero slope cases are accounted for properly, and assuming the edge lines point in a clockwise direction around the polygon (if it's counterclockwise, you'll get the outward normal instead of the inward one).
    so all I need to do is ordering the vertices in counterclockwise in my code to get the inward normal . cos in my code I have ordered them in a clockwise direction to get the area positive, I mean IS there any other way to distinguish between the in-upward normals.
    Quote Originally Posted by jemidiah
    Note that you're getting the the explicit equation for the line going through your (x0, y0) normal to the edge using your calculation and not an explicit normal vector. Calculating the vector is easy and can be done from the slope alone very easily if you draw it out.

    The normal at the edge points is really undefined. Cross products as mentioned won't help you. You might use the average normal vector, averaging the normals you get by considering each side alone. At least that should point inward, and it's probably the best definition you'll be able to find.
    why not defined i guess we can consider the normal on each segment which is normal on each point on it, I am right??yes Cross products doesn't fit here

  19. #19
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: normal at corner of rectangular

    So you still don't understand why a normal vector does not make sense at a point?

    Have a look at the following image, and try to answer my questions:


    Look at figure (a). Which of the three vectors is normal to the point?

    Look at figure (b). The blue vectors are normal to the polygon. When you shift these normals towards a common point (indicated by the black arrows) eventually you reach the case of the two red vectors.
    Which of the two red vectors is normal to the polygon at the common point?

  20. #20
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: normal at corner of rectangular

    I'm pretty sure Sally understands that the normal isn't defined at the corner from this, though the picture of course says the reason why elegantly:
    Quote Originally Posted by Sallygreen
    the normal vector at the corner is undefind cos we working in 2-dim
    As I recall you said you wanted the vectors to generally point towards the center of the polygon. If your line segment vectors (the ones you generate a normal from by making a perpendicular vector using <a, b> goes to <b, -a>) point clockwise, you'll get inward normals. Note that you can use <a, b> goes to -<b, -a> = <-b, a> to get outward normals. This can be seen easily from a box with top edge segment vector <1, 0> with normal <0, -1>. You'll get the outward normal from a counterclockwise pointing of your line segment vectors. But if you accidentally get outward normals you can just compute your line segment vectors in reverse by swapping the edge vertices in the distance formula, or take the negative of your outward normal to get your inward normal. But regardless, here's what you want:

    You've got vertices v1 through vn ordered clockwise. Find the inward normal ni on edge ei as defined in my other post in the other thread. Using the same idea as your formula from an earlier post, "v_1=(x1,y1) and v_2=(x2,y2) is v=(x2-x1,y2-y1), then the normal vector is v=(y2-y1, -(x2-x1))," we can do the following. Note that taking v2-v1 points clockwise around the circle, so taking v as you have should indeed yield the outward normal. In general, ni = (y_i+1 - yi, -(x_i+1 - x_i)). You don't have to mess with the slope stuff you were doing earlier--I only mentioned it in my previous post because you hadn't mentioned doing this purely with vectors and I didn't want to add another object to the mix.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  21. #21

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    Quote Originally Posted by jemidiah
    I'm pretty sure Sally understands that the normal isn't defined at the corner from this, though the picture of course says the reason why elegantly:
    you always understand what I mean exactly
    Quote Originally Posted by jemidiah
    As I recall you said you wanted the vectors to generally point towards the center of the polygon. If your line segment vectors (the ones you generate a normal from by making a perpendicular vector using <a, b> goes to <b, -a>) point clockwise, you'll get inward normals. Note that you can use <a, b> goes to -<b, -a> = <-b, a> to get outward normals. This can be seen easily from a box with top edge segment vector <1, 0> with normal <0, -1>. You'll get the outward normal from a counterclockwise pclockwiseointing of your line segment vectors. But if you accidentally get outward normals you can just compute your line segment vectors in reverse by swapping the edge vertices in the distance formula, or take the negative of your outward normal to get your inward normal. But regardless, here's what you want:

    You've got vertices v1 through vn ordered clockwise.
    I think it is cheaper if we can order the vertices rather than do checking every time for the segments direction mmmm the only thing I know how to check weather the vertices ordered clockwise or counterclockwise?e,g. for a concave polygon if its area positive then its vertics ordered in counterclockwise direction and vice versa. But for the convex polygon is different, i.e if the cross product of all 2 adjacent segment is positive then its vertics ordered in counterclockwise direction.
    so I guess in my code I need to order the vertices in clockwise direction? But how can I do that?
    Last edited by Sallygreen; Nov 6th, 2008 at 06:25 AM.

  22. #22

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    Quote Originally Posted by NickThissen
    No, you don't need the t, it is simply a scalar: you have a vector (-b, a) which points in the direction of the line, and you multiply that vector by an arbitrary t, (t ranging from - infinity to + infinity) to get the entire (infinitely long) line.

    I actually meant the fact that the vector (a, b) is perpendicular (normal) to the vector (-b, a).
    A line in two dimensions can also be represented as a vector. The vector along the line
    ax+by=0
    (10)

    is given by
    t[-b; a],
    (11)

    where t in R. Similarly, vectors of the form
    t[a; b]
    (12)

    are perpendicular to the line.
    These equations you had referred to in your thread, as far as I can see these inf. restricted to the lines which pass the origin point (0,0) not for any line?? but I think we still can do some shift to the vertex point each time. I dont know if my thought make sense

  23. #23
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: normal at corner of rectangular

    All I meant you to see was that a vecotr (a, b) is perpendicular to a vector (-b, a) or (b, -a). That is the key point in calculating normals to lines in 2 dimensions. But I understand you know that now?

  24. #24
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: normal at corner of rectangular

    I assume you're given a list of the vertices either in clockwise or counterclockwise order (if not, the polygon described by those vertices is almost certainly not unique). So you just want to check which order they're in? You could use the property that any line drawn through a polygon must cross it an even number of times. Then start on an arbitrary edge, find the normal, and collision detect a line *moving in the direction of the normal from the edge* to see how many segments it passes through. If it's an inward normal it starts inside the polygon and eventually will pass through an odd number of edges to get out. If it's an outward normal it starts outside the polygon and will pass through an even number of edges (usually 0) to get out.

    If we use only convex polygons it'll probably get lots simpler. This is just what occurs off the top of my head, there are likely better ways to check orientation.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  25. #25

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    Quote Originally Posted by jemidiah
    I assume you're given a list of the vertices either in clockwise or counterclockwise order (if not, the polygon described by those vertices is almost certainly not unique). So you just want to check which order they're in? You could use the property that any line drawn through a polygon must cross it an even number of times. Then start on an arbitrary edge, find the normal, and collision detect a line *moving in the direction of the normal from the edge* to see how many segments it passes through. If it's an inward normal it starts inside the polygon and eventually will pass through an odd number of edges to get out. If it's an outward normal it starts outside the polygon and will pass through an even number of edges (usually 0) to get out.

    If we use only convex polygons it'll probably get lots simpler. This is just what occurs off the top of my head, there are likely better ways to check orientation.
    .........this way seems to be quite complicated to be coded,,,it might be helpful if there is another way to do it

  26. #26

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    Quote Originally Posted by jemidiah
    As I recall you said you wanted the vectors to generally point towards the center of the polygon. If your line segment vectors (the ones you generate a normal from by making a perpendicular vector using <a, b> goes to <b, -a>) point clockwise, you'll get inward normals. Note that you can use <a, b> goes to -<b, -a> = <-b, a> to get outward normals. This can be seen easily from a box with top edge segment vector <1, 0> with normal <0, -1>.
    just wanna to make sure is this way of finding th normal to a vector general???or just for the lines which cross the origin point (0,0) as it said in the link sended by Nick in the posts above

  27. #27
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: normal at corner of rectangular

    A vector in general is an object with a length, and a direction. A vector does not have a position. That means that if you want to find the normal to a line, only the slope of the line matters! The slope defines the direction of the normal vector, and the length of the vector is either 1 (after you normalize it) or any arbitrary value. The position of the vector is not usually something you use, so if you have 5 lines with identical slopes, but different x and y-intercepts (imagine a few parallel lines above each other) then the normal vectors to each line will be identical.

  28. #28
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: normal at corner of rectangular

    Yeah, the distinction is between a vector and a line as Nick suggests. The <a, b> goes to <-b, a> or <b, -a> thing will give you a vector normal to the first vector. In your case you create the first vector by subtacting the end points of an edge from each other, which necessarily creates a vector (not a line). So yeah you just have to be careful about accounting for that.

    Like I said there are probably simpler ways to figure out orientation but I've at least given you a valid way of doing it. Maybe you can find a better algorithm lying around on the internet.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  29. #29

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    Quote Originally Posted by jemidiah
    I'm pretty sure Sally wants to find the normal to each edge segment, pointing inward.

    In that case the formula posted above (the one with m_n->-1/m_n) should be fine assuming the zero slope cases are accounted for properly, and assuming the edge lines point in a clockwise direction around the polygon (if it's counterclockwise, you'll get the outward normal instead of the inward one).
    Would it be enough to order the vertices of the polygon clockwise to get the inward normal? or do I have to check each edge whether it is point in clockwise or anticlockwise??

  30. #30
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: normal at corner of rectangular

    You can just ensure the vertices are oriented in whichever way I've been saying they should be oriented (it's in two of the above posts, I don't wanna hunt for it now). The "orientation" of an edge really makes no sense. Consider a box centered on the origin. If you compute your edge vectors in a silly manner, both the top and bottom edge's vectors could be pointing, say, left. They're the same vectors, but one of them is clearly clockwise (the bottom one) and the other is counterclockwise (top).

    In the same way it doesn't make sense to ask about the orientation of the vector given by an edge in vacuo. You have to consider the entire polygon as a whole. So yeah, just make sure the vertices are arranged like I described and it'll work out. I'm pretty sure I was explicit in my original explanation, and boiled it down to a formula given a few well-marked assumptions; I'm not quite sure where the disconnect still lies.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  31. #31

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    Hi guyes

    Any help would be much appreciated, as I need to find the normal at the corner of rectangular, so would be possible to calculate the average normal at the both sides of the rectangular, so we will get the normal at the corner in 3 dim, does this calculation make any sense in 2 dim ?????????

  32. #32
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    Re: normal at corner of rectangular

    I still don't really understand what your after. At first I thought that you wanted to treat the rectangle sides as vectors (choosing directions of course) and compute the normal but after reading all these posts I'm not sure.

    Anyway, I'll just give an example of what I thought you meant at first and maybe that will help or at least get us talking about what you're after. Where you are computing the normal determined by treating the line segments as vectors. Let's assume that we have a rectangle with vertices A, B, C and D with x,y coordinates of each vertex being (ax, ay), (bx, by), (cx, cy) and (dx, dy) respectively. I'm assuming that this is 2D but this is easily extended to a 3D situation. It's an identical problem.

    So we have something like this:

    Code:
     
             A _____________________ B
               |                    |
               |                    |
               |                    |
               |                    |
               |____________________|
             D                      C
    (Excuse the crude drawing)


    Okay let's pick a direction convention. Let's so that all vectors will be chosen in the direction from A to B, B to C, C to D and D to A. Of course, it's not necessary to choose this convention but you didn't specify so this is what I'm using.

    Okay So let's say we are going to compute a normal vector so that it is normal to both the line segments AB and BC. In order to do this, we first make vectors.

    Let,

    Vab, be the vector from point A to point B

    Vbc, be the vector from point B to point C


    so then

    Vab = (bx - ax) i + (by - ay) j

    Vbc = (cx - bx) i + (cy - by) j


    Okay so now we have our vector definitions. We can compute the a vector normal to both of these vectors by using the cross product. You can read up on how to do this here

    So for us our normal vector, let's call it N, can be obtained as:

    N = Vab X Vbc (X is the cross-product operator)

    If you read the wiki page you will know that N's magnitude will be given by the area of the rectangle (more generally a parallelogram). It's direction depends on the orientation of the Vectors Vab and Vbc. Since our vectors lie only in the x-y plane we know that N only have a k-component. Also we even know the direction from the right-hand rule. In our case N will point in the negative k direction.

    If you do the math you would compute N to be:

    N = [(bx - ax)(cy-by) - (by-ay)(cx-bx)] k


    I don' t know if that helps. If you could be more specific perhaps I could help more....

  33. #33
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: normal at corner of rectangular

    Sally I'm sorry but your wording is so non-specific I don't think anybody has a clue of what you're talking about anymore. We've been through most of the sane possibilities. If you can like draw pictures of what you have and what you want, maybe we could help. Barring that I doubt this will go anywhere new.

    P.S. @Wy in post 32: any normal will clearly be in the k hat direction with that setup; I don't believe the cross product's magnitude was ever asked for so you may as well skip the algebra and just use a unit normal N = 1k. Doesn't really matter, just that I saw some redundancy and wanted to note it is all.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  34. #34
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    Re: normal at corner of rectangular

    @jemidiah Yes, as I stated in my post, since the rectangle is in the X-Y plane any normal will have only a k-component. I did not mean to imply that there is only one normal either. I know it's a trivial example but it does show the steps and it can be extended to 3D very easily where the result is not so trivial. There are applications, like say 3d-graphics, where the direction of the normal (even with objects that only lie in a plane) is important and one would have to program the computation process.

    I guess the problem is that we don't know what sally is using this for (well at least i don't). I was hoping that my post would encourage some input from her to get what she is after.

  35. #35

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    please anyone could help out, I need to write a code which go through the area of a triangular to find the x-y coordinates for each point inside the triangular, let say I need to find 10, actually we can have some n in the code which is the desired number no of points. The problem I do not know how to scan all the points and make sure being inside the triangular I need to include some condition to control the program does not go outside the triangular, please can anyone give a hint
    Last edited by Sallygreen; Mar 12th, 2009 at 02:29 PM.

  36. #36
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: normal at corner of rectangular

    ?? Do you really need ALL points in a triangle, or do you only need n random points in that triangle?

    If the second assumption is true, you could "normalize" the triangle (One side is horizontal and on the x-axis). Take a random number between 0 and the heigth of that normalized triangle, that will be you Y-coordinate. Using that Y-coordinate, determine where the triangle intersects this coordinate, these x-Value are your minimum and maximum value to randomly pick the X-Coordinate of your point.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  37. #37
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: normal at corner of rectangular

    Quote Originally Posted by opus
    ?? Do you really need ALL points in a triangle, or do you only need n random points in that triangle?
    Presuming it's the second guess, you could do this in-place using some vector additions. Let the three points of the triangle be p1, p2, p3. (Let them be vectors; then it doesn't matter how many dimensions we're talking about.) Define v1 = p2 - p1, v2 = p3 - p2. If you draw it out, you'll see that taking certain unit linear combinations of v1 and v2 will allow us to reach any point in the triangle, if we start at the point p1.

    Thus pick two random numbers from 0 to 1, call them x1 and x2. Then a point P inside the triangle is given by

    P = p1 + x1*v1 + x1*x2*v2.


    Do this n times and you'll have your points. This method should be equivalent to Opus', though it hides the coordinate transformations. It relies heavily on similar triangles in the derivation.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  38. #38

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    Quote Originally Posted by jemidiah
    Presuming it's the second guess,
    you always getting me right , really appreciate your time
    PHP Code:
    p1 x1*v1 x1*x2*v2
    can I generate this formula to a rectangle and so on???

    Quote Originally Posted by jemidiah
    Do this n times and you'll have your points.
    wher shall I include n, I think I should choose x1=1/n, and x2=1/m, and run loop for that, cos if I fix x1,x2 I will get the sme point each time

  39. #39
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: normal at corner of rectangular

    You could do the same thing with a rectangle, though the formula would be

    P = p1 + x1*v1 + x2*v2.

    This would also work for a parallelogram.

    You can pick n points either by choosing n different, random values for x1 and x2, or by doing as you suggest and choosing x1 = 1/i, x2 = 1/j for i=1...n and j=1...m (though this second method would loop n*m, not just n, times).
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  40. #40

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    53

    Re: normal at corner of rectangular

    Quote Originally Posted by jemidiah
    This would also work for a parallelogram.
    it would also work for a polygon yes??? as I need my code to geeneral for any geometry....but mainly for a polygon
    Quote Originally Posted by jemidiah
    You can pick n points either by choosing n different, random values for x1 and x2, or by doing as you suggest and choosing x1 = 1/i, x2 = 1/j for i=1...n and j=1...m (though this second method would loop n*m, not just n, times).
    I've done that
    Code:
    do i = 2,n
               do j = 2,m
                  px(i,j)=x(1)+(1/i)*vx(1)+(1/j)*vx(2)
                  py(i,j)=y(1)+(1/i)*vy(1)+(1/j)*vy(2)
              end do
          end do
    wher vx(1) is the x coordinate of the v1=p2-p1, and so..... but it is not giving me the right answer....... I should be doing something wrong, but where is it??/
    Last edited by Sallygreen; Mar 15th, 2009 at 08:56 AM.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width