Re: [QUIZ] Triangle Area (#160)



On 4/21/08, Todd Benson <caduceass@xxxxxxxxx> wrote:

I suppose another way to approach it could be to use a matrix
transformation to get your 'base' (turn the triangle, or the
coordinate system; however you prefer to see it) and use a simple
1/2(b*h).

1/2(b*h) wa the first thing I thought of when I read the quiz title.
Here's my implementation:

class Triangle
def area
pts = [@a, @b, @c]
#filter out degenerate triangles
return 0 if pts.uniq!

#move one point to the origin
offset = pts[0]*-1.0
pts.map!{|v|v+=offset}

#find the angle of one leg
angle=Math::atan(pts[1][1]/pts[1][0])

#rotate that leg so it lies along X axis
rotmat = Matrix.rows( [[Math::cos(angle),Math::sin(angle)],
[-Math::sin(angle),Math::cos(angle)]])
pts.map!{|v|rotmat*v}

#use basic geometry
base = pts[1][0].abs
height = pts[2][1].abs
area=base*height/ 2.0
end
end


-Adam

.



Relevant Pages

  • Re: Why vitzivanu lehadlik ner?
    ... For example, the USDA could ... "Pulling one's leg" is a figure of speech, ... equivalent to "pulling my leg," the meanings are too inter-related. ... your system it might be a triangle. ...
    (soc.culture.jewish.moderated)
  • Re: Re-adjusting a bad triangle
    ... >> Triangle from guard: Let's say you commited the fatal sin on not ... >> I know you can sometimes underhook their leg to spin, ... Grab under their knee to pull your body around. ... even with both hands on the side of the head. ...
    (rec.martial-arts)
  • Re: Re-adjusting a bad triangle
    ... > Triangle from guard: Let's say you commited the fatal sin on not ... > I know you can sometimes underhook their leg to spin, ... Grab under their knee to pull your body around. ... the ankle to keep the leg locked in and unhook your other leg and use it to ...
    (rec.martial-arts)
  • Re: Video of my comp today.
    ... leg could have been easily underhooked by your right arm.Epecially ... I don't even squeeze a triangle tight unless I can spin out enough ... that my left leg is touching his head his right arm is the one out ... triangle....Eddie Bravo says dont get your head out, ...
    (rec.martial-arts)
  • Re: Re-adjusting a bad triangle
    ... > Triangle from guard: Let's say you commited the fatal sin on not ... > I know you can sometimes underhook their leg to spin, ... You can jump your hips out to the side and get that 45 degree angle without ... This is often the problem when trying to get his trapped arm across center. ...
    (rec.martial-arts)

Loading