How do I create a 2nd ray with a script given I have a ray and an angle?

classic Classic list List threaded Threaded
4 messages Options
HJH
Reply | Threaded
Open this post in threaded view
|

How do I create a 2nd ray with a script given I have a ray and an angle?

HJH
This post was updated on .
Hello Hilaire

I have a script


   | c vertex pointB  ray ray2|
    c := DrGeoCanvas new.
    vertex := c point: 1@0.
    vertex name: 'vertex'.
    pointB := c point: 5@0.
    ray2 := c ray: vertexA to: pointB.

    ray := c "send a message with parameters ray2 and an angle, the origin of ray is vertex"

I like to create another  ray called 'ray' which has its initial point as vertex and is slanted by an angle of 30 degrees.

--Hannes
Reply | Threaded
Open this post in threaded view
|

Re: How do I create a 2nd ray with a script given I have a ray and an angle?

Hliaire Fernandes
Administrator
Hi,

Ok, got it. Just do as bellow:

 | c vertex pointB  ray ray2 |
    c := DrGeoCanvas new.
    vertex := c point: 1@0.
    vertex name: 'vertex'.
    pointB := c point: 5@0.
    ray2 := c ray: vertex to: pointB.
    ray := c ray: vertex to: (c rotate: pointB center: vertex angle: Float pi / 3 )

The angle is a Float, Dr. Geo will transform it as Free value item, hidden in the canvas. From the Dr. Geo user interface, you can later un-hide it to edit its value.

Another way, from the script, you can build a Dr. Geo Angle item from two vectors or three points, so in the canvas moving the vectors or the points will change dynamically the angle and ray2.

Hilaire
HJH
Reply | Threaded
Open this post in threaded view
|

Re: How do I create a 2nd ray with a script given I have a ray and an angle?

HJH
Thank you for the answer. This works well. I like that this can be written in a simple

     object keyword message

style.


    | c vertex pointB  pointC ray ray2 |
    c := DrGeoCanvas new.
    c gridOn.
    vertex := c point: 1@0.
    vertex name: 'vertex'.
    pointB := c point: 5@0.
    pointB name: 'B'.
    ray2 := c ray: vertex to: pointB.
    pointC := c rotate: pointB center: vertex angle: Float pi / 3.
    pointC name: 'C'.
    ray := c ray: vertex to:  pointC

ray obtained by rotating another ray

Follow up question: How do I make the angle of 60 degrees to be drawn?
HJH
Reply | Threaded
Open this post in threaded view
|

Re: How do I create a 2nd ray with a script given I have a ray and an angle?

HJH
Answer: Showing the angle

    | c vertex pointB  pointC ray ray2 angle|
    c := DrGeoCanvas new.
    c gridOn.
    vertex := c point: 1@0.
    vertex name: 'vertex'.
    pointB := c point: 5@0.
    pointB name: 'B'.
    ray2 := c ray: vertex to: pointB.
    pointC := (c rotate: pointB center: vertex angle: Float pi / 3 ).
    pointC name: 'C'.
    ray := c ray: vertex to:  pointC.
    angle  := c angle: pointB to: vertex to: pointC.
    angle show.

show angle, ray obtained by rotating another ray